On a CentOS 7 machine with cronie-1.4.11-14.el7_2.1.x86_64
, I can have two CRON_TZ
in one file. My crontab file reads:
CRON_TZ=Etc/GMT+0
* */2 * * * touch ~/temp/cron-0gmt0evenhour
* 1-23/2 * * * touch ~/temp/cron-0gmt1oddhour
CRON_TZ=Etc/GMT+1
* */2 * * * touch ~/temp/cron-1gmt0evenhour
* 1-23/2 * * * touch ~/temp/cron-1gmt1oddhour
1-23/2
means odd hours. See stackoverflow and serverfault.
Result (after it runs for long enough):
$ ll ~/temp/ --full-time
total 0
-rw-r--r-- 1 packard domain_users 0 2020-11-21 22:59:01.108221582 +0000 cron-0gmt0evenhour
-rw-r--r-- 1 packard domain_users 0 2020-11-21 23:25:01.177041834 +0000 cron-0gmt1oddhour
-rw-r--r-- 1 packard domain_users 0 2020-11-21 23:25:01.176041830 +0000 cron-1gmt0evenhour
-rw-r--r-- 1 packard domain_users 0 2020-11-21 22:59:01.108221582 +0000 cron-1gmt1oddhour
CRON_TZ
only controls the timing to start a job, so it is useful only if the job does NOT run on every hour (as Michael pointed out in a comment). Use TZ
to set the environment variable that the job sees.
Michael's answer (multiple cron files) would not be feasible for non-root users, who have only one crontab. And having multiple CRON_TZ
is useful to deal with different daylight-saving time in different time-zones.
ps. I got to know my version of cron from the following command inspired by this post.
$ rpm -qf `which crontab`
cronie-1.4.11-14.el7_2.1.x86_64