0

I am trying to get a simple systemd service to run on a timer unit. For some reason, systemd doesn't seem to like the way I am specifying time. The script worked when I used minutely or daily as the value for OnCalendar, but now I want to set it to 5 minutes and systemd gives an error:

/etc/systemd/system/backup.timer:7: Failed to parse calendar specification, ignoring: 5m
backup.timer: Timer unit lacks value setting. Refusing.

Thing is, according to this page, minutes should be an understood unit of time. They have 2hours as an example timespan that should work there, so I don't understand why 5m or 5minutes is somehow invalid.

Here is my timer file:

[Unit]
Description=Timer unit for backup.service
Requires=backup.service

[Timer]
Unit=backup.service
OnCalendar=5m

[Install]
WantedBy=timers.target

The other thing is, when I run systemd-analyze timespan 5minutes it does not return an error, and it seems to be able to parse the value correctly:

Original: 5minutes
      μs: 300000000
   Human: 5min
3
  • Looking for references, but I'm pretty sure OnCalendar= expects a time-stamp, not a time-span. For time-span, you probably want OnActiveSec= or OnBootSec=.
    – Stewart
    Commented Jul 26, 2022 at 12:09
  • That was it, thank you!
    – JLCarveth
    Commented Jul 26, 2022 at 12:11
  • Great, I'll write an answer.
    – Stewart
    Commented Jul 26, 2022 at 12:11

1 Answer 1

2

5m is a time-span. OnCalendar= expects a time-stamp.

According to systemd.time(7), a time-stamp is a unique point in time, while a time-span is a duration.

If you want to keep OnCalendar=, then use a time-stamp like:

  • minutely, hourly, daily
  • 2012-11-23 11:12:13
  • Mon,Fri *-01/2-01,03 *:30:45

If you do want to use a duration, then try OnActiveSec= or OnBootSec= which takes a duration and adds it to the time the unit became activated or the system booted. See systemd.timer(5) for more options such as OnUnitActiveSec= (when the timer was last triggered)

Defines realtime (i.e. wallclock) timers with calendar event expressions.

A calendar event expression is a "unique point in time".

1
  • This is a great answer thank you, especially for explaining why daily and minutely worked while the other values did not.
    – JLCarveth
    Commented Jul 26, 2022 at 12:28

You must log in to answer this question.

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