夏令时和Cron

Joe*_*e W 37 cron dst

如果Cron的工作计划在凌晨2点和凌晨3点运行,那么这些工作将如何受到夏令时的影响?

当时间向后移动一小时的时间是从上午2:59:59直到凌晨2:00:00吗?这意味着凌晨2点的工作会运行两次而凌晨3点的工作会运行一次?或者是时间首先变为凌晨3:00:00然后凌晨2:00:00导致两个作业都运行两次?

当时间向前移动一小时的时间是从早上1:59:59到凌晨3:00:00导致凌晨2点的工作没有运行而凌晨3点的工作运行一次?或者时间从2:00:00变为凌晨3:00:00,导致两个作业都运行一次?

简而言之,我想知道的是,当上午3点钟发生一次或两次时,一小时就会发生一小时,并且在凌晨2点钟就会发生一小时的损失.在Google上查看时,我无法找到任何相关信息.

mtk*_*mtk 38

答案取决于您使用的cron的变体/扩展.某些变体不处理夏令时,导致丢失作业和两次运行.

如果您使用的是Paul Vixie cron,那么它确实可以处理DST更改.根据cron手册页:

cron检查每一分钟以查看其假脱机目录的modtime(或/ etc/crontab上的modtime)是否已更改

此外,参考夏令时(第二段明确解释了你的答案)

夏令时和其他时间变化

   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.
Run Code Online (Sandbox Code Playgroud)

因此,每当时间变化可能是2:59:59或3:00:00时,cron通过处理情况并仅运行遗漏的工作并避免运行已经运行的作业来处理作业.

  • 链接已损坏。什么Paul Vixie cron。我在互联网上什么也没找到。 (2认同)
  • 以下是不存在页面存档的链接:https://web.archive.org/web/20130905110602/http://unixhelp.ed.ac.uk/CGI/man-cgi?cron +8和这是一个托管linux手册页的当前站点:https://linux.die.net/man/8/cron (2认同)