previous date comman in unix (urgent)

October 3, 2011 at 14:43:08
Specs: N/A
i want when i run my script in UNIX then it should autmoatically get previous day date and append it to a file name monitorBatch.log.

example: monitorBatch.log.2011-10-02

as i am running script on 2011-10-03 then it should append as i mentioned above:

monitorBatch.log.2011-10-02.

Please help me..its urgent


See More: previous date comman in unix (urgent)

Report •

#1
October 3, 2011 at 15:45:03
Manipulating dates in vintage unix without benefit of a scripting languarge is difficult. You can manipulate the timezone variable, TZ, to get yesterday's date and then create and write to a file:

#!/bin/ksh

YESTERDAY=$(TZ=aaa24 date +%Y-%m-%d)
echo $YESTERDAY

echo "some text" > monitorBatch.log.$YESTERDAY


This TZ thing is not portable, but this works on my Solaris 9 box. Your mileage may vary.

Unix date arithmetic has been discussed a lot on this forum. Here is one of many example links in this forum that discusses TZ, the shift_date shell script, and a suite of shell scripts that does date arithmetic:

http://www.computing.net/answers/un...


Report •

#2
October 3, 2011 at 16:35:45
Hi nails...

What does TZ=aaa24 means??


Report •

#3
October 3, 2011 at 17:19:14
AAA24 is an offset from GMT for the TZ variable. Here is a description:

http://www.mailarchive.ca/lists/com...


Report •

Related Solutions

#4
July 2, 2012 at 23:28:58
Hi,

It' not working as when I added the same to a script wherin it runs at 2:00 AM every morning and needs to take in count of the previous days file in a folder.
The date was caluclated for day before yesterday and the count also for the same.

My system timezone is of UAE
Tue Jul 3 10:24:17 GST 2012

Thanks and Regards,
Gowri Shankar
gowri.c91@gmail.com


Report •

#5
July 3, 2012 at 06:38:38
As I said, TZ is not portable. Based on your description, I don't know what the problem is.

If I were you, I'd consider using the shift_date shell script. I linked to it in my first reply.


Report •

Ask Question