Monday, April 08, 2013

Running jobs in different Timezones and Day light saving or DST by crontab

Oh, This day light saving thing. Why people don't set their whole environment clock on UTC ?
Believe me, I all will have better life if that happens.

Any way, The newer versions of crontab have introduced a good way to run job in different time zones. Just look at the following example of crontab file for instance.


#######################IMPORTANT#######################
# Anything beyond this line will run in Australia/Victoria time zone
#######################################################
CRON_TZ=Australia/Victoria
#######################################################

00 08 * * * /home/healthcheck/linux/send-email.sh

#######################IMPORTANT#######################
# Anything beyond this line will run in America/New_York time zone
#######################################################
CRON_TZ=America/New_York  
#######################################################

00 08 * * * /home/healthcheck/linux/syslog-check.sh

#######################IMPORTANT#######################
# Anything beyond this line will run in UTC time zone
#######################################################
CRON_TZ=UTC
#######################################################
01 16 * * * /home/healthcheck/linux/runDST.sh


And to check when this year's day light saving happens ?

[healthcheck@adm01 ~]$  zdump -v Australia/Victoria| grep `date +%Y`
Australia/Victoria  Sat Apr  6 15:59:59 2013 UTC = Sun Apr  7 02:59:59 2013 EST isdst=1 gmtoff=39600
Australia/Victoria  Sat Apr  6 16:00:00 2013 UTC = Sun Apr  7 02:00:00 2013 EST isdst=0 gmtoff=36000
Australia/Victoria  Sat Oct  5 15:59:59 2013 UTC = Sun Oct  6 01:59:59 2013 EST isdst=0 gmtoff=36000
Australia/Victoria  Sat Oct  5 16:00:00 2013 UTC = Sun Oct  6 03:00:00 2013 EST isdst=1 gmtoff=39600
[healthcheck@adm01 ~]$