14
Systemd Timer units (discuss.tchncs.de)

I am trying to create some systemd units that are supposed to start scripts at certain intervals. With Cron, I used an expression like 0 3 */7 * * to start a job every 7 days at 3 a.m. That worked great. With OnCalendar, I have no idea how to implement "every 7 days". Or can I use OnUnitActiveSec here? Additional problem: The computer is not always on at the specified time. The job should therefore be repeated as soon as the computer is available again. I have set Persistent=true for this purpose. However, I suspect that OnUnitActiveSec is reset every time I restart the computer. Or does OnUnitActiveSec refer to the time when the unit was activated with systemctl enabled test.timer?

top 10 comments
sorted by: hot top controversial new old
[-] nous@programming.dev 5 points 3 days ago* (last edited 2 days ago)

Note that you can use systemctl list-timers to see all active timers including when they will next run and when they last ran. This is very useful for seeing if you have set things up correctly.

There are multiple ways to do this as well. You can do

OnCalendar=Sun 03:00
Persistent=true

To run every Sunday at 3am. And will run immediately when activated if the last time was skipped due to the system being off. Think that is the closest to your cron job.

You can also

OnCalendar=weekly
Persistent=true

If you don't care when it will run. This is equivalent to Mon *-*-* 00:00:00.

[-] DeltaWingDragon@sh.itjust.works 1 points 2 days ago

Why does it say "Sun" if it runs on Saturday?

[-] nous@programming.dev 1 points 2 days ago

Typo on my part.

[-] MoLoPoLY@discuss.tchncs.de 2 points 3 days ago

Ahh even more possibility's. Many thx.

[-] HelloRoot@lemy.lol 4 points 3 days ago* (last edited 3 days ago)

OnCalendar is calendar-based, not interval-based.

Use a monotonic timer with OnUnitActiveSec=7d plus Persistent=true . This is not quite the same as your cron, because it can drift the day of ghe weak.

And no, it does not reset just because you reboot.

[-] MoLoPoLY@discuss.tchncs.de 3 points 3 days ago

Shifting the day of the week is totally fine, since i only care about days between the job executions. Many thx, then i try my luck with this.

[-] oranki@sopuli.xyz 3 points 3 days ago

Would something like

OnCalendar=Wed *-*-* 03:00:00

Technically not the same as every 7 days, instead it's every Wednesday.

[-] MoLoPoLY@discuss.tchncs.de 3 points 3 days ago

OK. I think 7 day was a slightly misleading schedule :-) My bad. But yes, you are right, for 7 days, this will work fine. But i think OnUnitActiveSec=7d is more flexible, when i change this to 12 days, 9 days and so on... I should learn to be more precise in my questions. Sorry.

[-] AstralPath@lemmy.ca 1 points 2 days ago

This might interest you. https://crontab.guru/

[-] adept@programming.dev 1 points 3 days ago

Check the man pages, starting with man systemd.time

this post was submitted on 04 Feb 2026
14 points (93.8% liked)

Linux Questions

3700 readers
27 users here now

Linux questions Rules (in addition of the Lemmy.zip rules)

Tips for giving and receiving help

Any rule violations will result in disciplinary actions

founded 2 years ago
MODERATORS