So, I'm using Anacron to be able to reliably run some scripts daily. However, this doesn't work when Anacron itself doesn't start on boot half the time. How would I get Anacron to start up reliably?
> 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)
As can be seen in the syslog, Anacron was only started at boot on May 20th and June 3rd, despite the machine being booted May 21st and 25th and June 1st.
Additionally, today (June 3rd), I actually booted my computer at 12:11, and seeing that Anacron had not started and none of my jobs were run, I rebooted the machine at 12:29. You can see on this second boot, Anacron decided to startup. Why does it just not startup a lot of the time?
Edit: This appears to have been fixed upstream in Debian 10 and Ubuntu 19.04.
So, it seems that Anacron doesn't run at startup if on battery power, and is only scheduled to run at 7:30am otherwise. The solution for me was to configure Anacron to run when power is plugged in.
This can be done by adding a script like this:
I saved it into
/etc/pm/power.d/10_anacron
(make sure it is executable), which on older systems would be run automatically when plugged in. On current versions of Ubuntu, you need to add a udev rule to run the script. Just save:to
/etc/udev/rules.d/anacron.rules
.An easier way: just change a line in the file
/etc/default/anacron
to: