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?

  • nous@programming.dev
    link
    fedilink
    English
    arrow-up
    5
    ·
    edit-2
    6 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.