Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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.

share|improve this answer
2  
Wow, knowledge from the 80s - Hats off! – Isaac Mar 29 at 13:25
    
rule of thumb: once a year your crons in that hour range won't run. once a year your crons will run twice. corollary: this isn't always true. related: stop using local time zones! – tedder42 Apr 4 at 17:46
    
@tedder42 please provide references, your claims contradict both the documentation and the actual behaviour of cron. – Anthon Apr 4 at 18:37
    
    
That anecdotal case references 2am and 3am and has no relevance to the question (which refers to 2:30) pm. Your references might be interesting (old) behaviour, it doesn't align with my experience. And running a server without timezone has its own problems. – Anthon Apr 4 at 20:16

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.

share|improve this answer
2  
A minor nitpick. UTC is not "Universal Time Constant". UTC means Coordinated Universal Time – fpmurphy1 Apr 2 at 7:11
    
@fpmurphy1 - thanks corrected. – Steve Barnes Apr 2 at 7:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.