Best way of dealing with cron and time differences?

Best way of dealing with cron and time differences?

Posted by: msephton
Posted on: 2006-08-22 05:18:00

I see that the time used by cron is server time. I need to run my script only during UK office hours (9h-18h), so have offset the times against PST (-8h).

However, I am aware that daylight savings time will mess this up. Sure, I could add an hour either side, but that's not an elegant solution.

What do other people think?

Re: Best way of dealing with cron and time differe

Posted by: aixccapt99
Posted on: 2006-08-22 06:37:00

Make cron run the script all the time (every 5 mins, every hour, or whatever you need), and put your timezone logic into the script so that it only performs its work during the time periods you want. This is also somewhat inelegant but leaves you 100% in control and less vulnerable to changes in the server setup.

Re: Best way of dealing with cron and time differe

Posted by: msephton
Posted on: 2006-08-22 06:48:00

I'll bear that in mind, for more granular control.

But I'm just wondering what other non-USA sites might do. I can't be the first to have this problem.

Re: Best way of dealing with cron and time differe

Posted by: netdcon
Posted on: 2006-08-22 07:50:00

In reply to:

But I'm just wondering what other non-USA sites might do. I can't be the first to have this problem.


Try putting this line:

export TZ=GMT

..in your ".profile", or just:

TZ=GMT

..as a line in your crontab file. Either one or both of these should work. If GMT isn't what you're after, use the "tzselect" command to help determine the correct TZ setting.


Re: Best way of dealing with cron and time differe

Posted by: msephton
Posted on: 2006-08-22 07:52:00

Thank you very much. I will read up about that, looks to be the best solution.

Re: Best way of dealing with cron and time differe

Posted by: msephton
Posted on: 2006-08-23 12:50:00

I eventually went for:

TZ="Europe/London"

at the top of my crontab file :)

Re: Best way of dealing with cron and time differe

Posted by: msephton
Posted on: 2006-08-24 15:37:00

Which... doesn't seem to work? Hmm.

Re: Best way of dealing with cron and time differe

Posted by: aito
Posted on: 2006-08-26 17:41:00

In my case I put this line in .bash_profile:
export TZ=Asia/Tokyo

Re: Best way of dealing with cron and time differe

Posted by: msephton
Posted on: 2006-08-29 03:07:00

Thanks, I will try that.

Tags: cronawareadd