Crond and timezones

I was going crazy for the last few days. I have set up an important job on the brand new CentOS5 server and it didn’t seem to run. Every morning I was rushing to start ssh and check the result, but alas, nothing to be seen. I was starting the script manually and cursing my Linux knowledge. What I should have cursed is my attentiveness to my earlier actions, one of which was setting a different time zone.

I was going crazy for the last few days. I have set up an important job on the brand new CentOS5 server and it didn’t seem to run. Every morning I was rushing to start ssh and check the result, but alas, nothing to be seen. I was starting the script manually and cursing my Linux knowledge. What I should have cursed is my attentiveness to my earlier actions, one of which was setting a different time zone.

As any admin knows a local timezone is an evil for the things like cron jobs which may be otherwise affected by the summer and winter time shifts otherwise. So what do you do? You set the UTC time. On CentOS you may do something like this (assuming you’re well-behaving, disabled the root account and doing all things under sudo):

sudo rm /etc/localtime
sudo ln -s /usr/share/zoneinfo/UTC /etc/localtime
sudo tzdata-update

What one should realize (and I didn’t) is that not all services will catch up with the new settings. And guess what, cron is one of them. So what you need to do is the following

sudo /etc/init.d/crond restart

This will make sure that cron is not left running with your originally set timezone (which was in my case about 6 hours away from me) and will behave according to the newly set timezone.