Best way of dealing with cron and time differences?

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?

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.

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.

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.

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

I eventually went for:


at the top of my crontab file :slight_smile:

Which… doesn’t seem to work? Hmm.

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

export TZ=GMT-9 also worked.

Thanks, I will try that.