[foxboro] Calculating yesterday for shell scripts on SOTM and P91

Hi all,
I sometimes need a shell script to be able to parse yesterday's and today's
information out of log files.  On the 51 series I can do:
#!/bin/sh
today=`date "+%Y-%m-%d"`
yesterday=`TZ=GMT+24 date "+%Y-%m-%d"`

date "+%Y-%m-%d" returns 2009-05-18, and TZ=GMT+24 date "+%Y-%m-%d" returns
2009-05-17.

When I tried this in shell scripts on the P91 (Win2003) and P82 (Solaris 10)
boxes it seemed to work, but when the scripts ran at 5am I'd get the wrong
results.  I finally realized that when I test this in the afternoon my
"yesterday" works fine, but at 5am it's returning 2 days ago.  So, lightbulb
goes off - I'm not on GMT with the P91 or P82.  When I check, TZ on the P82
is "Asia/Tokyo" and is "TST" (Tokyo Standard Time) on the P91.  Seems like
for date commands, TZ of TST = JST = Asia/Tokyo.

Unfortunately, when I try:
yesterday=`TZ=JST+24 date "+%Y-%m-%d"` or yesterday=`TZ=Asia/Tokyo+24 date
"+%Y-%m-%d"` or yesterday=`TZ=TST+24 date "+%Y-%m-%d"` in the script I get
exactly the same results.

Any of TZ=JST+15, TZ=TST+15, TZ=Asia/Tokyo+15, TZ=GMT+15 do give me the
right result however.  I'm at GMT+9, so I guess adding 15 more hours to that
makes it yesterday for people at GMT+0.  Unfortunately, this makes it
obvious I don't know what I'm doing, as this shouldn't work based on how I
thought TZ and "date" work.  I'm happy my scripts are working properly again
any time during the day, but would like to know what I'm doing wrong.

Thoughts anyone?

Cheers,

Kevin


 
 
_______________________________________________________________________
This mailing list is neither sponsored nor endorsed by Invensys Process
Systems (formerly The Foxboro Company). Use the info you obtain here at
your own risks. Read http://www.thecassandraproject.org/disclaimer.html
 
foxboro mailing list:             http://www.freelists.org/list/foxboro
to subscribe:         mailto:foxboro-request@xxxxxxxxxxxxx?subject=join
to unsubscribe:      mailto:foxboro-request@xxxxxxxxxxxxx?subject=leave
 

Other related posts: