The Linux Page

Since 22.04 (possibly 21.10?) anacron runs at the wrong time?!

Anacron Time Changed

After upgrading, I noticed that I was getting some results from my Anacron at 07:38 instead of the usual "around midnight" time (which was often off by 1h in winter and/or summer... but that was fine with me).

Anacron Settings on 22.04

So I looked around and found out that the setup to start the Anacron scripts, a calendar setup in systemd, is used on newer systems. The other scripts starting CRON will test whether anacron is installed then do nothing if so. The old anacron script will test whether systemd is installed and if so, again, do nothing.

Here is the default systemd setup for anacron as found on 22.04:

[Unit]
Description=Trigger anacron every hour

[Timer]
OnCalendar=*-*-* 07..23:30
RandomizedDelaySec=5m
Persistent=true

[Install]
WantedBy=timers.target

As we can see, the Anacron scripts will run between 07:00 in the morning and until 23:30 at night. Although I have a desktop on my computer, I still want the Anacron to run around midnight if possible.

Fix the Hours

So I edited this file using the following command:

sudo systemctl edit --full anacron.timer

Note: if anacron is not installed on your machine, this command fails. That's expected.

And I changed the OnCalendar= parameter like so:

OnCalendar=*-*-* 00:05..23:55

As a result, Anacron daily runs around midnight again.

See Anacron Timer

systemctl has a special list of units called timers (which really are "calendars") which can be listed like so:

systemctl list-timers

This will show you when the timer will wake up next. You should see that the anacron timer is listed if installed. You can search for it since systemctl uses less to page the output (/regex↵). You can also specify the name on the command line to just get the anacron unit:

systemctl list-timers anacron