20

Last weekend we had to change the time from 02:00 to 03:00.

Question: What would happen if there was a cronjob at 02:30?

crond is a very old solution for scheduling, it should probably handle it, but don't know how.

2 Answers 2

22

It probably depends on your cron implemenation, but the popular Vixie cron states in the manual:

cron then wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute.

and

Special considerations exist when the clock is changed by less than 3 hours, for example at the beginning and end of daylight savings time. If the time has moved forwards, those jobs which would have run in the time that was skipped will be run soon after the change. Conversely, if the time has moved backwards by less than 3 hours, those jobs that fall into the repeated time will not be re-run.

Only jobs that run at a particular time (not specified as @hourly, nor with '*' in the hour or minute specifier) are affected. Jobs which are specified with wildcards are run based on the new time immediately.

Since the DST change was less than 3 hours, your program would run shortly after 3:00 AM

I am not sure if this is Vixie cron specific behaviour, I seem to recall this is how my PDP-11 worked as well back in the 80s but I am not sure.

7
3

The best solution is to have your computer running with the hardware clock set to UTC, (Coordinated Universal Time), AKA GMT or Zulu Time and only change the way that the time is displayed by setting the local time zone to allow the Day Light Saving time to take over.

On SUSE Linux, and probably most others, if the Hardware Clock System -> Environment -> Clock -> HWCLOCK is set to UTC with the -u flag then and your time zone is set to where you are the system will automatically display local times with DST corrections for you.

This has a number of advantages:

  • You will never have to manually adjust the clock for DST changes again
  • CRON tabs will be stored in and executed at UTC times
  • If a file, e.g. a log, is written at 01:30 before the end of DST and another at 01:20 after the end of DST that file will still be "Newer" than the other one because the file timestamps will be UTC and just translated for display based on the current time zone at display time.

For more information type man hwclock in a terminal.

1
  • 2
    A minor nitpick. UTC is not "Universal Time Constant". UTC means Coordinated Universal Time
    – fpmurphy
    Apr 2, 2016 at 7:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .