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
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 $YESTERDAYecho "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:
Hi nails... What does TZ=aaa24 means??
AAA24 is an offset from GMT for the TZ variable. Here is a description:
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 2012Thanks and Regards,
Gowri Shankar
gowri.c91@gmail.com
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.