53

If Cron has a job scheduled to run at 2 am and one at 3 am how would those jobs be affected by daylight savings time?

When the time shifts back an hour does the time go from 2:59:59 am to 2:00:00 am directly? Meaning that the 2 am job would run twice and the 3 am job would run once? Or is does the time first change to 3:00:00 am and then 2:00:00 am causing both jobs to run twice?

When the time shifts forward an hour does the time go from 1:59:59 am to 3:00:00 am causing the 2 am job to not run and the 3 am job to run once? Or does the time shift from 2:00:00 to 3:00:00 am causing both jobs to run once?

In short what I am wondering is when gaining an hour does the 3 am hour happen once or twice and and losing an hour does the 2 am hour happen at all. I have not been able to find anything about this when looking on Google.

mtk
  • 13,221
  • 16
  • 72
  • 112
Joe W
  • 1,767
  • 2
  • 28
  • 37

2 Answers2

52

The answer would be dependent on the variant/extension of cron you are using. Some variants do not handle the Daylight Saving Time, leading to missing jobs and twice run of the job.

If you are using the Paul Vixie cron, then it does handle the DST changes. As per the cron man page:

cron checks each minute to see if its spool directory's modtime (or the modtime on /etc/crontab) has changed

And further, with reference to Daylight Saving Time (The 2nd paragraph clearly explains your answer)

Daylight Saving Time and other time changes

Local time changes of less than three hours, such as those caused by the start or end of Daylight Saving Time, are handled specially. This only applies to jobs that run at a specific time and jobs that are run with a granularity greater than one hour. Jobs that run more fre- quently are scheduled normally.

If time has moved forward, those jobs that would have run in the inter- val that has been skipped will be run immediately. Conversely, if time has moved backward, care is taken to avoid running jobs twice.

Time changes of more than 3 hours are considered to be corrections to the clock or timezone, and the new time is used immediately.

So, whenever the time shifts may be 2:59:59 or at 3:00:00, cron's taking care of the job runs by handling the situation and running only the missed ones and avoids running the already ran jobs.

Maksim Vi.
  • 9,107
  • 12
  • 59
  • 85
mtk
  • 13,221
  • 16
  • 72
  • 112
  • 2
    The link is broken. What Paul Vixie cron. I have found nothing on internet. – Ad Infinitum Dec 12 '16 at 12:12
  • 4
    Here is a link to an archive of the non-existent page: https://web.archive.org/web/20130905110602/http://unixhelp.ed.ac.uk/CGI/man-cgi?cron+8 and here is a current site that hosts linux man pages: https://linux.die.net/man/8/cron – Nick Rempel Feb 22 '17 at 20:31
0

To make it clear, it depends on where you live, how your cron jobs are scheduled (Unix cron which you need to take care of, while Java scheduler which take care by itself!).

In the U.S., clocks change at 2:00 a.m. local time. In spring, clocks spring forward from 1:59 a.m. to 3:00 a.m.; in fall, clocks fall back from 1:59 a.m. to 1:00 a.m.

In the EU, clocks change at 1:00 a.m. Universal Time. In spring, clocks spring forward from 12:59 a.m. to 2:00 a.m.; in fall, clocks fall back from 1:59 a.m. to 1:00 a.m.

Example: if you have a Unix cron job at 1:30 am on today 25 October 2020, your jobs run twice.

Valerio Bozz
  • 1,176
  • 16
  • 32
surya kiran
  • 465
  • 5
  • 10
  • It should be clear from my question which time change I am talking about as I specify the hours before and after the change. This is also different than the accepted answer as well. – Joe W Oct 25 '20 at 15:40