1

I'd like to restrict the time of day the jobs set in anacrontab are allowed to run.

I can find in man pages online info about START_HOURS_RANGE which is supposed to do precisely that. For example here and here. Some questions on this site also mention this setting, e.g. Job `cron.daily' started not append in /var/log/cron and In what cases will anacron not run?.

However, the man page for anacrontab in my system (Mint 19) does not include such setting. Indeed, even if I include:

START_HOURS_RANGE=5-17

in my \etc\anacrontab, anacron jobs do not restrain to this time range.

It would seem from it that this setting has been dropped by anacron, though I couldn't find any release notes to pinpoint this.

So, my question is, given the above, how then could I restrict the time of day anacron's jobs start?

gusbrs
  • 183
  • 1
    The first two links to man pages on the Net mention Fedora at the bottom. If you are on Debian, there is no START_HOURS_RANGE in the installed man pages. – nst0022 Dec 02 '18 at 14:26
  • @nst0022 This might very well be the source of the difference, and not a "drop" by anacron as I assumed, thank you. But still, not only does it not figure in the man pages in my system, but it also doesn't work. So I'm looking for a way to achieve it. – gusbrs Dec 02 '18 at 14:33

1 Answers1

2

Assuming you’re using systemd (which is the default on Linux Mint 19), you can override the anacron timer. Run

sudo systemctl edit anacron.timer

then, in the editor which opens, enter

[Timer]
OnCalendar=
OnCalendar=*-*-* 05..17:00

or whatever time range you prefer. The empty OnCalendar entry is necessary to clear the existing calendar entries. See the systemd.time manpage for details of the time syntax, and the systemd.timer manpage for details of timer definitions.

Note that, starting with version 2.3-27~exp1 of the package, the default systemd timer runs only between 7:30 and 23:30.

On systems running anacron with cron rather than systemd, you can override the time range in the /etc/cron.d/anacron file. If you have both cron and systemd, anacron runs using the latter, so the timer takes precedence.

With both approaches, your changes will be preserved across package upgrades.

Stephen Kitt
  • 434,908
  • Stephen, thank you very much! Indeed, I haven't changed anacron's defaults, so I must be running on systemd. I'll have to try things out here, but it seems to be the point. I'll also edit the question to state that this is distro specific, which I didn't assume originally, so that this is better searchable for others. – gusbrs Dec 02 '18 at 20:20
  • Tests went smoothly here, and the solution is spot on. Once again, thank you. – gusbrs Dec 03 '18 at 09:34