Systemd Timer Configuration – Run Every X Days at 04:00

cronlinuxsystemd

I have been reading on

OnCalendar=

Sadly, I found no info on how to schedule an event on a day other way than defining a day of the week, which would make it run every week at the rarest.

I need it to run every, say, 14 days. And at a specified hour (say, 4am). Is this possible with systemd?

Best Answer

I need it to run every, say, 14 days. And at a specified hour (say, 4am). Is this possible with systemd?

The easiest way to get approximately every 14 days is to make it twice a month.

[Install]
WantedBy=default.target

[Unit]
Description=Every fortnight.

[Timer]
OnCalendar=*-*-1,15 4:00:00
Unit=whatever.service

That syntax is explained in man systemd.timer; *-*-1,15 is the 1st and the 15th of every month of every year.

If you wanted to try for exactly every fourteen days from when the service started:

[Timer]
OnActiveSec=14d

But there's a catch here: I think you'd have to have the system up the whole time. There is a Persistent option to have "the time when the service unit was last triggered...stored on disk" but according to the man page "this setting only has an effect on timers configured with OnCalendar".

Related Question