brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: one systemd timer can have several OnCalendar= lines

Systemd
~/tips/tip-systemd-timer-multiple-oncalendar

[Unit]

Gives one timer several schedules, such as different times on weekdays and weekends.

A job that should run at 07:30 on weekdays but at 10:00 on weekends doesn’t need two timers. One timer unit can carry both schedules.

The systemd.timer page says OnCalendar= may be specified more than once, and the timer fires whenever any of the expressions elapses. You can even mix calendar and monotonic settings in the same unit.

# /etc/systemd/system/report.timer
[Unit]
Description=Morning report

[Timer]
OnCalendar=Mon..Fri 07:30
OnCalendar=Sat,Sun 10:00

[Install]
WantedBy=timers.target

Both lines start report.service. After a sudo systemctl daemon-reload, systemctl list-timers report.timer shows whichever of the two comes next. To check both expressions in one go, systemd-analyze calendar takes several at once.

The caveat is in drop-ins. Because the lines add up, a systemctl edit override with a new OnCalendar= doesn’t replace the shipped schedule, it adds a second one. To replace it, put an empty assignment first:

[Timer]
OnCalendar=
OnCalendar=Sun 04:00

The empty line resets the list, and the manual adds that it clears the monotonic timers in that unit as well. That’s the step I’d double-check when a timer from a package suddenly runs twice as often as you expect.

Further reading: systemd.timer(5) manual page, systemd.time(7) manual page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link