2

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?

  • Did you read "CALENDAR EVENTS" in man systemd.time? "The weekday specification is optional." Etc. There's a bunch of examples there too. – goldilocks Mar 19 '15 at 18:00
3

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".

  • Thank you for your answer. That cleared up some things for me. I think I'll stick to cron as it does the same thing but does not require additional .service and .timer files, and instead keeps all jobs and timers in one clearly legible file. – lockheed Mar 21 '15 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.