Reputation: 31
I have two Cron jobs in my web server -
*/5 0-3 * * 0-4 [my job]
*/5 19-23 * * 0-4 [my job]
We are in the GMT+6 timezone, and the server is in GMT-8 timezone. We would like the job to run -
Sunday to Friday 9 AM to 5 PM at GMT+6 timezone (office hours) Every 5 minute interval
But it appears that the cron job runs on Fridays and also stops at Sunday noon at GMT+6 zone.
Upvotes: 3
Views: 4202
Reputation: 3398
This article helped me http://starikovs.com/2011/12/21/cron-timezone-problem/.
Upvotes: 2
Reputation: 25596
I'm not aware of any easy way to change the timezone. Some older versions of cron
supported an environment variable called CRON_TZ
, but the current version of cron
doesn't seem to.
So you'd have to convert the times to system time.
I think you have calculated the times correctly, and the days correctly, but you have to take them together. For example, 5pm on Thursday at UTC+6 is 3am on Thursday at UTC-8, but your rules aren't running anything on Thursday.
By my calculations, you want:
Sunday 0900-1700 UTC+6 = Saturday 1900-2400 and Sunday 0000-0300 UTC-8
Monday 0900-1700 UTC+6 = Sunday 1900-2400 and Monday 0000-0300 UTC-8
...
Thursday 0900-1700 UTC+6 = Wednesday 1900-2400 and Thursday 0000-0300 UTC-8
Friday 0900-1700 UTC+6 = Thursday 1900-2400 and Friday 0000-0300 UTC-8
Which you would express in crontab
as:
*/5 19-23 * * 0 [my job]
*/5 0-3,19-23 * * 1-4 [my job]
*/5 0-3 * * 5 [my job]
This solution doesn't feel that good, however.
What happens when daylight savings changes? Will you need to update the crontab
?
Maybe if you have root
access, you can modify the /etc/init.d/cron
entry and put TZ=America/Los_Angeles
or similar in there instead?
Of course, that solution sounds bad too, especially if other people use the system. Might as well just change the system's time zone if you're doing that.
Unfortunately there's not a lot of suggestions for alternatives to cron alternative to cron?
Upvotes: 2