所以,我使用 Anacron 来每天可靠地运行一些脚本。但是,当 Anacron 本身有一半时间没有在引导时启动时,这不起作用。如何让 Anacron 可靠启动?
> grep 'anacron' /var/log/syslog.2
May 18 19:09:02 s-laptop anacron[2480]: Job `cron.daily' terminated (exit status: 1) (mailing output)
May 18 19:09:02 s-laptop anacron[2480]: Can't find sendmail at /usr/sbin/sendmail, not mailing output
May 18 19:09:02 s-laptop anacron[2480]: anacron: Can't find sendmail at /usr/sbin/sendmail, not mailing output
May 18 19:09:02 s-laptop anacron[2480]: Normal exit (1 job run)
May 18 21:20:48 s-laptop systemd[1]: Started Run anacron jobs at resume.
May 20 16:30:46 s-laptop systemd[1]: Started Run anacron jobs at resume.
May 20 17:02:27 s-laptop systemd[1]: Started Run anacron jobs at resume.
May 20 18:58:50 s-laptop systemd[1]: Started Run anacron jobs at resume.
May 20 19:13:48 s-laptop systemd[1]: Started Run anacron jobs.
May 20 19:13:48 s-laptop anacron[734]: Anacron 2.3 started on 2017-05-20
May 20 19:13:48 s-laptop anacron[734]: Will run job `cron.daily' in 5 min.
May 20 19:13:48 s-laptop anacron[734]: Will run job `cron.weekly' in 10 min.
May 20 19:13:48 s-laptop anacron[734]: Jobs will be executed sequentially
May 20 19:18:51 s-laptop anacron[734]: Job `cron.daily' started
May 20 19:18:51 s-laptop anacron[2367]: Updated timestamp for job `cron.daily' to 2017-05-20
> grep 'anacron' /var/log/syslog.1
May 20 19:18:54 s-laptop anacron[734]: Job `cron.daily' terminated (exit status: 1) (mailing output)
May 20 19:23:48 s-laptop anacron[734]: Job `cron.weekly' started
May 20 19:23:48 s-laptop anacron[2606]: Updated timestamp for job `cron.weekly' to 2017-05-20
May 20 19:30:09 s-laptop anacron[734]: Job `cron.weekly' terminated
May 20 19:30:09 s-laptop anacron[734]: Normal exit (2 jobs run)
May 21 10:02:56 s-laptop systemd[1]: Started Run anacron jobs at resume.
May 25 12:53:39 s-laptop systemd[1]: Started Run anacron jobs at resume.
Jun 1 18:09:14 s-laptop systemd[1]: Started Run anacron jobs at resume.
Jun 3 12:29:40 s-laptop anacron[751]: Anacron 2.3 started on 2017-06-03
Jun 3 12:29:40 s-laptop anacron[751]: Will run job `cron.daily' in 5 min.
Jun 3 12:29:40 s-laptop anacron[751]: Will run job `cron.weekly' in 10 min.
Jun 3 12:29:40 s-laptop systemd[1]: Started Run anacron jobs.
Jun 3 12:29:40 s-laptop anacron[751]: Will run job `cron.monthly' in 15 min.
Jun 3 12:29:40 s-laptop anacron[751]: Jobs will be executed sequentially
Jun 3 12:34:40 s-laptop anacron[751]: Job `cron.daily' started
Jun 3 12:34:40 s-laptop anacron[2243]: Updated timestamp for job `cron.daily' to 2017-06-03
> grep 'anacron' /var/log/syslog
Jun 3 12:34:44 s-laptop anacron[751]: Job `cron.daily' terminated (mailing output)
从系统日志中可以看出,Anacron 仅在 5 月 20 日和 6 月 3 日启动时启动,尽管机器在 5 月 21 日和 25 日以及 6 月 1 日启动。
另外,今天(6 月 3 日),我实际上在 12:11 启动了我的计算机,并且看到 Anacron 没有启动并且我的作业都没有运行,我在 12:29 重新启动了计算机。您可以在第二次启动时看到,Anacron 决定启动。为什么它只是不启动很多时间?
编辑:这似乎已在 Debian 10 和 Ubuntu 19.04 的上游修复。
因此,如果使用电池供电,Anacron 似乎不会在启动时运行,否则仅计划在上午 7:30 运行。我的解决方案是将 Anacron 配置为在插入电源时运行。
这可以通过添加这样的脚本来完成:
我将它保存到
/etc/pm/power.d/10_anacron
(确保它是可执行的)中,它在旧系统上会在插入时自动运行。在当前版本的 Ubuntu 上,您需要添加一个 udev 规则来运行脚本。只需保存:到
/etc/udev/rules.d/anacron.rules
.更简单的方法:只需将文件中的一行更改
/etc/default/anacron
为: