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?

  • HelloRoot
    link
    fedilink
    English
    arrow-up
    5
    ·
    edit-2
    2 months 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.deOP
      link
      fedilink
      English
      arrow-up
      3
      ·
      2 months 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.

    • MoLoPoLY@discuss.tchncs.deOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 month ago

      It seems that this doesn’t work as expected. Please see my new post from today. I have found also the following issue https://github.com/systemd/systemd/issues/3107. According to this, a monotonic timer doesn’t survive a reboot or power off. Please correct me, if I’m wrong.

      If I understand this correctly, only a onCalendar type can be used here. That’s a little bit annoying, but as of yet, I haven’t found a way around this.

      • HelloRoot
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 month ago

        oh shit thats really weird systemd design…