Cron task in a different time zone

Is there a way to configure cronjob for a specific time zone?

My shared hosting is in the USA (Virginia), and I am in the UK. If I set a cron job that will run at 1600 every Friday, it will run when its 1600 in Virginia.

I was wondering if I can configure my cronjob so that it understands which time zone to choose. I'm not too concerned about the difference in summer time.

I asked my hosting providers about this and they said that I can set the time zone in some cron ini files, but I could not find them.

+8
cron
source share
4 answers

I think you should check

/etc/default/cron 

or just type

 Crontab cronfile 

and you should find

 TZ=UTC 

This needs to be changed (e.g. America / New_York). The second path is set in the cron example

 5 2 3 * * TZ="America/New_York" /do/command > /dev/null 2>&1 
+5
source share

You can use the CRON_TZ environment CRON_TZ , excerpt from man 5 crontab on a CentOS 6 server:

CRON_TZ indicates the time zone for the cron table. Type the user in the selected table once at the time of the specified time zone. Time in the log is taken from the local time zone where the daemon is running.

So, if you add this to the beginning of your cron entry:

 CRON_TZ=Europe/London 

You must be good.

+4
source share

If you want to set a different time zone for your specific cronjob, do crontab -e via ssh and add

 TZ=Europe/Moscow 

before each cronjob.

Full article here

+3
source share

To extend the answer to AlexT:

 CRON_TZ="Europe/London" 

- the answer.

ps If anyone here is looking for timezone fixes for GoDaddy, I recommend putting ...

 export TZ="Europe/London" 

... in your .bashrc so that your console starts in your time zone.

+1
source share

All Articles