13

There are several good references on systemd timers including this one:

systemd.time

Unfortunately, it still isn't clear to me how to create a timer that will run periodically, but at a specific number of minutes after the top of the hour.

I want to create a timer that runs 30 minutes past the hour, every 2 hours. So it would run at 14:30 (2:30 pm), 16:30, 18:30, 20:30, etc.

I tried several things that did not work, including this:

OnCalendar=*-*-* *00/2:30

And this:

OnCalendar=*-*-* *:00/2:30

I did not find the time specification to produce the desired result.

Also, it does not have to run exactly at that moment, so I was thinking about using:

AccuracySec=5m
2
  • You should use RandomizedDelaySec=5m instead of AccuracySec for the purpose. Jan 31, 2018 at 9:38
  • Edit: not available on systemd-analyze 219. Need to upgrade
    – MrSo
    Jan 31 at 19:52

2 Answers 2

24

Every 2 hours at 30 minutes past the hour should be

OnCalendar=00/2:30
#   iow    hh/r:mm

00/2 - the hh value is 00 and the repetition value r is 2 which means the hh value plus all multiples of the repetition value will be matched (00,02,04..14,16..etc)
30 - the mm value, 30 will match 30 minutes past each hour

I left the date and the seconds out since, per the same man page:

date specification may be omitted, in which case the current day [...] is implied [...]If the second component is not specified, ":00" is assumed.

3
  • 1
    Forgive my ignorance, I am still trying to digest the systemd timer grammar... Would every 4 hours be OnCalendar=00/4:00?
    – user56041
    Mar 28, 2019 at 22:02
  • @jww - that is correct. As to your other Q - try to specify Unit=ftc-data.service under [Timer] before (or after) OnCalendar... And btw, you don't enable the service, only the timer. Mar 28, 2019 at 23:08
  • Thanks @don. Unit=ftc-data.service did not help. Does crontab still work on new Fedora systems? I'm happy use it to avoid dicking around with systemd problems.
    – user56041
    Mar 28, 2019 at 23:35
9

Solution for for future readers:

    # systemd-analyze calendar --iterations=2 '0/2:30:00'            
      Original form: 0/2:30:00
    Normalized form: *-*-* 00/2:30:00
        Next elapse: Fri 2023-01-20 16:30:00 EET
           (in UTC): Fri 2023-01-20 14:30:00 UTC
           From now: 1h 22min left
           Iter. #2: Fri 2023-01-20 18:30:00 EET
           (in UTC): Fri 2023-01-20 16:30:00 UTC
           From now: 3h 22min left
3
  • 1
    This just repeats the solution given in the accepted answer. Jan 20, 2023 at 16:53
  • 1
    But it’s much clearer
    – Frizlab
    Aug 8, 2023 at 13:18
  • 1
    After searching for a moment, I found this helpfull command "systemd-analyze calendar" ! Thx +1
    – MrSo
    Jan 31 at 19:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .