Operating System - HP-UX
1755506 Members
3677 Online
108834 Solutions
New Discussion юеВ

Re: "date" command in a script

 
SOLVED
Go to solution
Jessica Chou
Advisor

"date" command in a script

Hi!
I used the following two lines to generate a filename for daily export dump file.

seqid=`date -u +%m%d`
filename=exp_$seqid.dmp

However, the number i got from "date" was
always one day earlier than the system exact day. The output of "ls -l" is like
-rw-r--r-- 1 oracle oinstall 7933952 Jan 8 05:50 exp_0107.dmp
-rw-r--r-- 1 oracle oinstall 7968768 Jan 9 05:50 exp_0108.dmp
-rw-r--r-- 1 oracle oinstall 8438784 Jan 10 05:50 exp_0109.dmp


And the wired thing is, if i run
date -u +%m%d
at the shell prompt now, i got the expected number "0117" as for today(Wed Jan 17 11:25:27 EAT 2001).
What's wrong here?

Please help.

Jessica
5 REPLIES 5
Vinit Adya
Frequent Advisor

Re: "date" command in a script

I think the date you are generting is beore taking the dump. So if its before midnight, you will get the previous days date.
ls command lists the date/time when the dump file was last updated. Which is 0500 hours of the next day. If this is true then the script is behaving as expected. If you wish to update the dte when the dump files actually complete, just rename the file using the same script after the dump is created.
Hope it helps...
Dan Hetzel
Honored Contributor

Re: "date" command in a script

Hi Jessica,

As Vinit told you, there is a great chance that your 'date' command runs before midnight and that the dump finishes at 05 AM the next day.

You could start your dump using a temp file, and once finished move (rename) your temp file to the real name using your 'date' construct, like in:
mv tmp_file exp_`date -u +%m%d`.dmp

This would ensure that the file name is showing the date you want, i.e. the end_of_dump date.

Best regards,

Dan

Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Jessica Chou
Advisor

Re: "date" command in a script

Hi,
thanks for your suggestion. I will try it.
(use a temp name, then rename it.)
However, I didn't run "date -u +%m%d" before midnight. "date" and Oracle's "exp" command
were included in the same script which then triggered by a crontab that set as:
50 5 * * 1-5 /mypath/my_dump.sh 2>> /mypath/dump_err.log

In my_dump.sh, it has
# Oracle environment variables. (skipped)
# ....
seqid=`date -u +%m%d`
/oraclehome/bin/exp USERID=system/manager FULL=Y INCTYPE=incremental DIRECT=Y FILE=/BACKUP/exp_$seqid.dmp LOG=/mypath/exp_i.log

#####

Jessica
John Palmer
Honored Contributor
Solution

Re: "date" command in a script

Hi Jessica,

The problem is due to you using the '-u' flag on the date command. This causes date to respond with the date in Coordinated Universal Time which equates to Greenwich Mean Time.

When your job runs at 05:50 EAT, this is either 22:50 or 23:50 the previous day GMT. When you ran the command at 11:25 EAT, GMT was the same day.

Simply remove the -u flag from the date command and you will get the correct day.

Regards,
John
Rick Garland
Honored Contributor

Re: "date" command in a script

Using the -u switch to the date command indicates that you want the date for UTC as opposed to your local TZ. Drop the -u switch from the date command.