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?

*/20  *  *  *  *  root /home/user/ >/dev/null 2>&1
*/5  *  *  *  *  root /home/user/ >/dev/null 2>&1

And then:

*/5  *  *  *  *  root /home/user/ >/dev/null 2>&1
*/10  *  *  *  *  root /home/user/ >/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:

25 12 * * * root echo Chicago >> /tmp/TZ

And /etc/cron.d/new_york:

25 13 * * * root echo New_York >> /tmp/TZ

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


View the full question and any other answers on Server Fault.

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