Systemd timer OnCalendar every minute ending with 5

With OnCalendar systemd timer i can create something like this to run every 5 minutes.

OnCalendar=*:0/5

Is it possible to run it at every minute ending at 5 (00:05, 00:15, 00:25...) only?

And/or at every minute ending with a 0 (00:00, 00:10, 00:20...) only?

Main goal is to have a timer on 2 server, so each one runs at spare times; in case one fails, the other will at least run every 10 minutes (instead of 5).


Solution 1:

Solution:

OnCalendar=*:5/10

which is equivalent to *:5,15,25,35,45,55.

To be sure of the result, use something like:

systemd-analyze calendar --iterations=8 '*:5/10' | grep Iter
       Iter. #2: Sun 2022-02-20 00:25:00 CET
       Iter. #3: Sun 2022-02-20 00:35:00 CET
       Iter. #4: Sun 2022-02-20 00:45:00 CET
       Iter. #5: Sun 2022-02-20 00:55:00 CET
       Iter. #6: Sun 2022-02-20 01:05:00 CET
       Iter. #7: Sun 2022-02-20 01:15:00 CET
       Iter. #8: Sun 2022-02-20 01:25:00 CET

Solution 2:

I am not sure if this varies from distro to distro. In any case, I am using RHEL8. Try this:

[Timer]
OnCalendar=*-*-* *:05,15,25,35,45,55:00

Use the systemctl daemon-reload command to make sure that systemd is aware of the changes.

Note: You should not edit files under the /usr/lib/systemd directory. With systemd, you can copy the unit file to the /etc/systemd/system directory and edit that copy.