Crontab for different ime zones
GT
catch.all at marketmentat.com
Mon May 25 02:21:17 UTC 2009
On Sun, 2009-05-24 at 18:45 -0600, Tim Judd wrote:
> How about a jail for America/NY, and a jail for AU/Sydney? that might
> work.
>
>
> --TJ
>
That's a good solution, but I am still somewhat puzzled by cron's
behaviour relative to what I expected from the man page.
>From the man page for crontab(8):
"In order to provide finer control over when jobs execute, users can
also set the environment variables CRON_TZ and CRON_WITHIN. The
CRON_TZ variable can be set to an alternate time zone in order to
affect when the job is run. Note that this only affects the scheduling
of the job, not the time zone that the job perceives when it is run.
If CRON_TZ is defined but empty (CRON_TZ=""), jobs are scheduled with
respect to the local time zone."
Problem is, CRON_TZ just doesn't work as written above.
If you insert CRON_TZ=America/New_York and then write the * * * * * (schedule)
to reflect NY time (say), but your server time is Chicago, cron ignores
the CRON_TZ definition.
Here's a CRONTAB extract which provides a good example of
the odd behaviour:
# ----- sample crontab
# change tz and cron_tz to America/NY
TZ=America/New_York
CRON_TZ=America/New_York
# check that timezone change 'stuck' (commented out except for testing)
* * * * * printf "CRON_TZ is now "$CRON_TZ". Now doing US\n" >> /home/targetdir/public_html/tmp/log.txt 2>&1
* * * * * date >> /home/targetdir/public_html/tmp/log.txt 2>&1
# Now, change both TZs to Australia/Sydney
TZ=Australia/Sydney
CRON_TZ=Australia/Sydney
# check that timezone change 'stuck' (commented out except for testing)
* * * * * printf "CRON_TZ is now "$CRON_TZ". Now doing Australia\n" >> /home/targetdir/public_html/tmp/log.txt 2>&1
* * * * * date >> /home/targetdir/public_html/tmp/log.txt 2>&1
# ----- end sample crontab
The result of that will be
Mon May 25 11:02:01 EST 2009
CRON_TZ is now Australia/Sydney. Now doing Australia
Sun May 24 21:02:01 EDT 2009
CRON_TZ is now America/New_York. Now doing US
'date' is right, and $CRON_TZ changes as expected, but has no effect in cron.
One other thing strikes me as odd: the output file is in reverse order
to the crontab. If changes to CRON_TZ actually worked as written, then one would
need to verify that the changes propagated 'downstream' from the variable declaration.
It's not that output is being written to the top of the outfile though - output
in subsequent minutes is APPENDED to the outfile.
And now for the big "DUH, I'm an idiot" moment - apparently FreeBSD, Fedora and Ubuntu don't have CRON_TZ support built in.
It's gotten to the stage where you have to be wary of what you find in external man pages...
Cheers
GT
More information about the freebsd-questions
mailing list