cron 每天什么时候执行脚本?

Mal*_*rba 39 cron-jobs scripts cron

如果我将一个 shell 脚本放在 中/etc/cron.daily/,它将在一天中的什么时间执行?

Dai*_*hiF 43

大约早上 7:35,但确切的时间取决于 anacron。

默认情况下,cron 将 /etc/cron.daily 作业的运行委托给 anacron。/etc/crontab 包含以下行:

25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
Run Code Online (Sandbox Code Playgroud)

但这定义了未安装anacron 时的行为

安装 anacron 后,cron.daily 作业的运行由 /etc/anacrontab 中的条目控制:

1   5   cron.daily   nice run-parts --report /etc/cron.daily
Run Code Online (Sandbox Code Playgroud)

这表示每天运行一次这些作业,延迟 5 分钟。

anacron 本身由 cron 运行,如文件 /etc/cron.d/anacron 中所指定,它在早上 7:30 运行 anacron。


Oct*_*ean 41

查看/etc/crontab它应该在06:25运行。

17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
Run Code Online (Sandbox Code Playgroud)

  • 这很可能是错误的,因为默认情况下安装了 anacron。另一个答案是正确的。 (7认同)
  • 是的,这个答案通常具有误导性。如果安装了 anacron,请参阅@DaithiF 的回答。 (3认同)

小智 10

如其他答案所示,结果取决于是否安装了 anacron。在桌面上,它默认安装,但关键是它没有安装在服务器发行版中。所以答案是在服务器上大约 06:25 和在桌面上大约 07:35。