11

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
don_crissti
  • 79,330
  • 30
  • 216
  • 245
MountainX
  • 17,168
  • 59
  • 155
  • 264

2 Answers2

22

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.

don_crissti
  • 79,330
  • 30
  • 216
  • 245
  • 1
    Forgive my ignorance, I am still trying to digest the systemd timer grammar... Would every 4 hours be `OnCalendar=00/4:00`? –  Mar 28 '19 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. – don_crissti Mar 28 '19 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. –  Mar 28 '19 at 23:35
5

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
Arto P
  • 51
  • 1
  • 1