13

I have cronjobs setup to be run daily on my Ubuntu server.

eg. 0 4 * * * command

They are running except they are running 8 hours early. When setting up the server, it was originally set to UTC time. I ran sudo dpkg-reconfigure tzdata to set the server to CST which is 6 hours behind UTC. Interestingly, I am in PST which is 8 hours behind UTC but I don't see how the server could know that.

If I run the command date, it shows the time in CST.

There must be some place that the time is configured wrong. Where can I look to solve this?

Matt McCormick
  • 243
  • 2
  • 4
  • 10

3 Answers3

25

Did you remember to restart cron after changing your time zone? If not, cron may still have its old notion of the time zone from when it was originally started.

While not strictly necessary I usually suggest rebooting a machine after changing the time zone -- A server's time zone shouldn't ever change (or at least it should be VERY infrequent), and this guarantees that every program on the server has been restarted and knows about the change :-)

voretaq7
  • 79,345
  • 17
  • 128
  • 213
  • No, I didn't restart. I have done that and will wait to see if that is the problem (which I think it may be). – Matt McCormick Feb 04 '11 at 16:45
  • After restart cron service, it's now run at the time same with timezone that I have set using tzdata. Thanks. – Donny Kurnia Dec 29 '14 at 23:51
  • 1
    I noticed the entries in /var/log/cron were showing the wrong time even after restarting crond. Restarting rsyslog fixed that issue. – zymhan Aug 11 '15 at 15:36
  • @WildVelociraptor Yeah syslog will also use the old timezone data until restarted (so it's going to timestamp things wrong even though they're running at the right time). Anything else that's long-running and started before the timezone data changed will exhibit similar behavior, which is why a reboot is generally indicated. – voretaq7 Aug 11 '15 at 16:46
  • Remember? Common sense would dictate that cron would read the system time, not keep it's own record of time. How would we know to "remember" to do that? – thistleknot Mar 23 '22 at 13:40
7

For me, I found that when I run the hwclock command the time was an hour different than when I ran the date command. To fix that you can call hwclock --systohc which will sync the two times and run the cronjobs at the expected time.

ajon
  • 309
  • 4
  • 11
0

On Ubuntu 20 restart the cron daemon with:

sudo service cron restart

crmpicco
  • 221
  • 1
  • 3
  • 11