Cron Timezone
Did you know you can set the time zone for cron?
Time is complicated
See FalsehoodsAboutTime.com for plentiful examples from amusing to horrifying.
Using computers for automated tasks is easy
Say you want to run a task at the same time every day. This is easily accomplished with the cron utility. First there's a crond daemon that always runs and has the ability to run scripts on your behalf. There are the usual quirks to be aware of, like "what permissions does the script need" and "what assumptions does cron's environment make" and of course "where do the error messages go".
But once you have all that down you can use a terse syntax to specify something like "run this task at 5am every day":
0 5 * * * /some/task.sh
You can even redirect the output of that task to somewhere more convenient than /var/log/cron, like so:
0 5 * * * /some/task.sh > /tmp/my_script.log
However, easy + time = complicated
You might think "what about time zones" and naively hope that cron will "do what I mean".
But in my opinion, the most important fallacy that programmers believe about time is that doing anything involving time will be easy, predictable, or intuitive.
Say you want to run a cron task at 5am EDT using cron. What are your options?
- the system time zone is EDT, and you haven't overridden defaults anywhere - cron will Just Work (TM)
- the system time zone is UTC, and you haven't overridden defaults anywhere - first you must Do The Math (TM) and then after that cron will work
- you can override defaults in the crontab (the file crond reads to decide what task to do and when)
Be aware though that overriding the default time zone in the crontab file will set the time zone for all the tasks in that file.
So for example if you have two tasks, one running at 5am and the other at 6am:
0 5 * * * /some/task.sh 0 6 * * * /other/task.sh
You can set the time zone separately for different tasks, but be aware that setting the time zone affects all the tasks that follow it:
0 5 * * * echo "run at 5am, system time - whatever that happens to be" CRON_TZ=America/Denver 0 6 * * * echo "run at 6am Mountain time" 1 6 * * * echo "run at 6:01am Mountain time" CRON_TZ=America/New_York 0 6 * * * echo "run at 6am Eastern time" # OOPS! copy-pasted first rule but made a bug by accident 0 5 * * * echo "still Eastern time"