systemd OnCalendar syntax, with the cron equivalents

On this page

An OnCalendar expression has up to three parts, a weekday, a date and a time, written as Mon..Fri *-*-* 09:00:00. It sets when a systemd timer fires, the way five fields do for a crontab line. Most cron schedules translate directly, and systemd-analyze calendar shows when an expression will run before you rely on it.

What is the format of an OnCalendar expression?

format
DayOfWeek Year-Month-Day Hour:Minute:Second
  • The weekday is optional. Mon, Mon,Fri and Mon..Fri all work.
  • The date is Year-Month-Day, and the time is Hour:Minute:Second. Each part accepts * for every value, a list with commas, a range with .. and a repeat with /.
  • Leave out the time and it means midnight; leave out the date and it means every day.
  • *:0/15 is every 15 minutes, counting from minute 0 of every hour.

Because there is a seconds part, a timer can fire at a precise second. The cron monitor on this site accepts only OnCalendar lines whose runs are at least 60 seconds apart.

How do you convert a cron expression to OnCalendar?

CronOnCalendarRuns
*/15 * * * **-*-* *:00/15:00Every 15 minutes
0 * * * **-*-* *:00:00 or hourlyAt the start of every hour
0 2 * * **-*-* 02:00:00Every day at 02:00
0 9 * * 1-5Mon..Fri *-*-* 09:00:00At 09:00 on weekdays
0 0 1,15 * **-*-01,15 00:00:00At midnight on the 1st and 15th
30 2 * * 0Sun *-*-* 02:30:00At 02:30 every Sunday

These are the forms the cron generator and dialect converter writes. Paste any five-field line into it to get the OnCalendar form and a note about anything that does not translate.

Which shortcuts does OnCalendar accept?

ShortcutSame as
minutely*-*-* *:*:00
hourly*-*-* *:00:00
daily*-*-* 00:00:00
weeklyMon *-*-* 00:00:00
monthly*-*-01 00:00:00
quarterly*-01,04,07,10-01 00:00:00
semiannually*-01,07-01 00:00:00
yearly*-01-01 00:00:00

weekly is Monday, while cron's @weekly is Sunday, so a straight swap changes the day.

How do the weekday and the date combine?

Differently from cron. In a crontab line with both day fields set, a match on either one runs the job. In OnCalendar the weekday is a filter on top of the date, so both must match: Mon *-*-01..07 03:00:00 runs only on a Monday that falls in the first seven days, which is the first Monday of the month. Cron cannot say that in one line; see the cron syntax cheat sheet for its rule.

A tilde counts days from the end of the month. *-*~1 is the last day of every month, and Mon *-05~07/1 is the last Monday in May, a schedule that no single cron line can express.

How do you test an expression before you use it?

shell
systemd-analyze calendar "Mon..Fri *-*-* 09:00:00"
systemd-analyze calendar --iterations=5 "*-*-01,15 00:00:00"

The first command prints the expression in its normalized form and the next time it fires. --iterations prints several runs, which is the quickest way to check a schedule. You can also see the next runs on any cron line in the next run calculator.

What else belongs in the timer?

  • Persistent=true runs a job that was missed while the machine was off, once, at the next start. Cron has no equivalent.
  • RandomizedDelaySec= spreads start times over a window, which keeps a fleet from all starting at once.
  • AccuracySec= allows systemd to delay a run to save wakeups. It defaults to one minute.
  • A trailing time zone, such as daily UTC, fixes the zone. Without it the expression follows the machine's time zone; see cron time zones and daylight saving time.

To watch a timer, ping from the service it starts, as in the systemd timers guide, and read cron vs systemd timers to choose between the two.

Sources

Questions and answers

How do I run a systemd timer every 5 minutes?
Use OnCalendar=*:0/5. It fires at minutes 0, 5, 10 and so on of every hour. For a fixed gap after the last run rather than a clock time, use OnUnitActiveSec=5min instead.
What does OnCalendar=daily mean?
The same as *-*-* 00:00:00: every day at midnight in the machine's time zone. Add a time, such as *-*-* 02:00:00, to move it.
Can systemd run something every 30 seconds?
systemd accepts a seconds part, such as *:*:0/30. A CronMissed check cannot be that frequent: the shortest interval it accepts is one minute.
Does OnCalendar run a job that was missed while the machine was off?
Only with Persistent=true in the timer. Without it, the run is skipped, as it is in cron.
Know the moment a job goes quiet

Create a check, add one curl to the job, and CronMissed alerts you when a ping is late or reports a failure.

Start monitoring