Date format conversion in AIX server - date

I am using AIX server.
I have a variable containing date returned from database i.e.
$ echo $date_var
12-JAN-17
Now i want to convert this string into yyyymmdd format.
I issued the following command
date -d $date_var +%Y%m%d
But I am getting error:
date : illegal operation --d
I think AIX server does not support this functionality. What can I do instead?

Could not add comment hence posting it as answer.
Can you check -u switch. reference link

Related

Can I pass a .sql file to psql?

I'm trying to pass a sql file to psql. After reading the docs, tried:
psql_args=(
"password='$INPUT_PASSWORD'"
dbname=analytics
"host='$INPUT_HOST'"
user=analytics
port=32648
file=query.sql
)
psql "${psql_args[*]}"
psql: error: invalid connection option "file"
root#380773cb4e26:/#
If I remove the file=query.sql arg this results in a connection to psql. I just don't know how to pass it a query file?
On the docs, two arguments look like ones of interest here:
-f filename
--file=filename
Read commands from the file filename, rather than standard input
and also:
-c command
--command=command
Specifies that psql is to execute the given command string, command
I tried the file=query.sql one but that failed with the error message above.The command one wants a string whereas I want to pass a .sql file. I tried anyway:
psql_args=(
"password='$INPUT_PASSWORD'"
dbname=analytics
"host='$INPUT_HOST'"
user=analytics
port=32648
command=query.sql
)
psql "${psql_args[*]}"
psql: error: invalid connection option "command"
Is there a way that I can pass query.sql to psql in order to run a query?
You seem to be packaging options up into a connection string. But --file must be given directly as an option to psql, not as part of a connection string.
psql "${psql_args[*]}" --file=query.sql
Since other answer seem to overlook this.
Here is how to store dynamic options into an array, and pass it as arguments to the command:
#!/usr/bin/env bash
psql_args=(
"--dbname=analytics"
"--host=$INPUT_HOST"
"--user=analytics"
"--port=32648"
"--file=query.sql"
)
psql "${psql_args[#]}"

Can’t use Mozilla’s cert9.db with certutil.exe

The following command: certutil.exe -L -d “C:\Users\Home\AppData\Roaming\Mozilla\Firefox\Profiles\1bku2z91.default-1633392324717\”
returns this error message: certutil.exe: function failed: SEC_ERROR_LEGACY_DATABASE: The certificate/key database is in an old, unsupported format.
I tried with and without quotes, changed backslash to forward slash. I found comments that the destination folder has to include secmod.db, which my folder does not but I think this applied to cert8.db, not cert9.db. I am passing the right folder as per about:support lookup. My Firefox version is 66.0.3
you need to add "sql:" before the location of the folder to specify that is a sqlite db that you are trying to read so it would be:
certutil.exe -L -d sql:“C:\Users\Home\AppData\Roaming\Mozilla\Firefox\Profiles\1bku2z91.default-1633392324717\”

How to start a exe with parameters in a batch file?

I have the problem,that the following code doesn't work.
start "" "datetime.exe" +%s -d "!timestamp!">tmp_datetime.txt
in cmd it works well, the variable timestamp is in the right Format.
for cmd I type the following
datetime.exe +%s -d "YYYY-MM-ddTHH:mm:ss"
and back comes the date as unix timestamp.
After running my Batch file with the start command, the tmp_datetime.txt is empty
Please try to use "call" instead of "start". Start will open a new window. I think there goes the problem with.
So try this one:
call datetime.exe +%s -d "!timestamp!">tmp_datetime.txt

How to convert any date to YYYYMMDDHHMMSS using unix shell script?

How to convert any date to YYYYMMDDHHMMSS using unix shell script?
It is not specific date it may any date. how to convert it?
example date format is: 20110101050603
Thanks
Puspa
DATE = "15 Jun 2015 10:10:10"; date -d"$DATE" +%Y%m%d%H%M%S
Output :-
20150615101010
More on Dates
Note this only works on GNU date.
I have read that:
Solaris version of date, which is unable to support -d can be resolve with replacing sunfreeware.com version of date.
Update:-
Use ls command to find all files and use grep command for all files.
ls | grep "[0-9]{14}"
grep command also accepts regular expression.
But it won't validate your file accurate. For example, if a file name is 20151835101010, then it will validate this file. But actually month and date both are wrong.
So my suggestion is to write a shell script to identify valid file name and find oldest of them by processing one by one.

How can I use mwdumper with Postgresql command line

I was importing a MediaWiki database using mwdumper with MySql. Now I need to do the same thing, but using Postgresql.
Basicly I get a archive in this link:
http://dumps.wikimedia.org/enwiki/20140903/
And I use mwdumper program to get informations and put in my database.
This is the database script:
https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2Fpostgres%2Ftables.sql
I created the database through this sql, and now I need to use mwdumper to put data in my database.
I saw many links about this, but only to do in MySql.
Anyone know how to do this import using Postgres, using command line?
Mwdumper: www.mediawiki.org/wiki/Manual:MWDumper
I forgot this question, but I found the solution, the command line to use mwdumper with postgres is:
java -jar mwdumper-1.16.jar --format=pgsql:1.5 ARCHIVE.xml.gz | psql -U wikiUSER -d wikiDATABASE
The command isn't wrong, the errors that happen is because the mwdumper-1.16 convert xml to sql with wrong sintaxe.
This is a insert sql after convert mwdumper (XML->PostgreSql):
INSERT INTO revision (rev_id,rev_page,rev_text_id,rev_comment,rev_user,rev_user_text,rev_timestamp,rev_minor_edit,rev_deleted) VALUES (378187747,676,378187747,'there is no such thing as \"Jr.\" in Russian names. sincerely yours, X\\'ZZ\\'',0,'198.240.130.75','2010-08-10 14:55:48',0,0);
Analizing the same insert in my data base Mysql, the expected text in Postgres is:
INSERT INTO (...) ,' there is no such thing as "Jr." in Russian names. sincerely yours, X\''ZZ\'' ', (...).
For example:
To represent double quotes, mwdumper give a sintaxe \" , but to represent " in Postgres doesn't have \ , it's just ". The same idea to others sintaxe errors.
When you solve all sintaxe errors you can dump perfectly.