Multiple instances of CRON_TZ inside a cron file (CentOS)

Borsn asked:

Is it possible to have multiple timezones in the /etc/crontab file, like below?

CRON_TZ=Europe/Paris
*/20  *  *  *  *  root /home/user/script.sh >/dev/null 2>&1
*/5  *  *  *  *  root /home/user/script1.sh >/dev/null 2>&1

And then:

CRON_TZ=UTC
*/5  *  *  *  *  root /home/user/watchdog.sh >/dev/null 2>&1
*/10  *  *  *  *  root /home/user/watchdog1.sh >/dev/null 2>&1

I’ve also tried TZ=Europe/Paris and export TZ=Europe/Paris instead of CRON_TZ before each line. But it didn’t work like that.


I don’t want to change the original timezone of the server which is UTC. Just want to run certain tasks in different timezones.


How can I use multiple timezones like this?

My answer:


I don’t think you can put both timezones in /etc/crontab, but you can make different files in /etc/cron.d each of which has a different CRON_TZ and TZ setting.

For instance, /etc/cron.d/chicago:

CRON_TZ=America/Chicago
25 12 * * * root echo Chicago >> /tmp/TZ

And /etc/cron.d/new_york:

CRON_TZ=America/New_York
25 13 * * * root echo New_York >> /tmp/TZ

At 17:25 UTC, the content of /tmp/TZ is:

Chicago
New_York

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.