Crontab for different ime zones

GT catch.all at
Sun May 24 04:17:39 UTC 2009

Late entry to this thread, but...

I thought I had found an answer to this; at present I think I might have
been mistaken.

My crontab has about a dozen jobs that need to run in
TZ=America/New_York, and another dozen that ideally want
TZ=Australia/Sydney... the server default is America/Chicago.

Given that the DST wobble for Australia/Sydney is not the same as for
America/New_York (and given that I am lazy) I wanted ONE crontab that
would serve year-round, rather than FOUR crontabs that had to be swapped
in and out all the time (even if that could be done by a cron job).

I thought I had found a solution - simply insert a line 


before the US jobs, and 


before the Australian ones. A final statement to return TZ to sever
default would be optional.

I checked that TZ changes worked, by adding a cron job (for testing
purposes) under each TZ declaration, of the form

    * * * * * date >> /home/mysite/public_html/tmp/log.txt 2>&1


    * * * * * date >> /home/mysite/public_html/tmp/log.txt 2>&1

Sure enough, every minute, cron would dutifully change TZ to NY and
change again to Sydney. There would be two datestamps in log.txt - one
would show current US/NY time, one would show current Australia/Sydney

Oddly they would appear in REVERSE order in the output file (Sydney
first, then NY).

If I run a very simple PHP script after each TZ declaration - for
example, one that writes date("Y-m-d H:i e") to the same log file - the
PHP script returns the server default timestamp (US/Chicago). So the
script does not 'see' the TZ (that is not a problem since my work
scripts don't have any internal time dependencies - the only time
dependency is the START time).

Also, if I time the script as if cron is actually 'seeing' Sydney time,
the scripts don't execute as expected. 

Example: it is currently 1:45 pm Sydney time. If I change 

    * * * * * date >> /home/mysite/public_html/tmp/log.txt 2>&1


    * 13 * * * date >> /home/mysite/public_html/tmp/log.txt 2>&1

cron will NOT run the script... I bet it will wait until 13:00 CHICAGO

I have a feeling that I am missing something relatively simple - at
which point my dream of a super-cron will be realised and the stupidity
of DST can be ignored (as it ought to be... ). I also bet that someone
else has worked this out already, somewhere in the internets tubes...
but i have been unable to find it. 

More information about the freebsd-questions mailing list