Talk:Crontab
It is supposed to be possible to change the timezone (as seen by cron) from within the crontab; if the server TZ is, say, CDT, cron's TZ can be changed by a line
TZ=America/New_York
To verify that this works, simply add a cron job immediately after it...
* * * * * date >> /tmp/log.txt 2&>1
you will find that log.txt does in fact show a timestamp for the timezone you chaged to using 'TZ='.
That said, there is a big issue with it, to which I have been unable to find a solution on the internets tubes.
The problems are besrt illustrated by an example.
My example: I have a crontab that runs a dozen or so jobs that depend on US/NY time, and another dozen that depends on Australia/Sydney time.
Different timezones move to and from daylight savings at different times, so I wanted ONE crontab that served year-round, rather than 4 different crons that I had to remember to swap out on the appropriate dates. Thus CRON_TZ seemed perfect.
BUT...if I do
TZ=America/New_York
# check that TZ change stuck (uncomment for testing)
* * * * * date >> /tmp/log/txt 2&>1
* * * * * /usr/bin/curl http://mysitename.com/dir/TimeCheck_US.php -o /dev/null >/dev/null 2>&1
# US data jobs
.
.
.
.
.
# end US data jobs
TZ=Australia/Sydney
# check that TZ change stuck (uncomment for testing)
* * * * * date >> /tmp/log/txt 2&>1
* * * * * /usr/bin/curl http://mysitename.com/dir/TimeCheck_AU.php -o /dev/null >/dev/null 2>&1
# Australian data jobs
.
.
.
.
.
# end Australian data jobs
each of the 'TimeCheck_XX.php' (XX in [US, AU]) scripts are simply
<?php
$testtime= date("Y-m-d H:i e");
$output="Testtime is ".$testtime." (should be XX time) and script executed without error\n";
file_put_contents('../tmp/log.txt',$output,FILE_APPEND);
?>
The problems that arise:
(1) unreliability of output - the log.txt file shows that the Auastralian timestamp gets written to log,txt BEFORE the US datestamp despite appearing AFTER it in the crontab. The output from the two TimeCheck scripts are BOTH appended AFTER the output of the two date jobs (you would expect date, TimeCheck_US, date, TimeCheck_AU);
(2) no change to the PHP timestamp - the two 'TimeCheck' php files both report the default (CDT) time;
(3) cron seems to ignore the new timezone despite printing it to file (e.g., if the time in Australia is known to be 11:05 a.m., and the date and TimeCheck_AU.php cronjobs are changed to * 11 * * *, NOTHING HAPPENS.
- Please ask questions in a forum. --ThorstenStaerk 07:16, May 24, 2009 (UTC)