December 4, 2026

systemd Timers and OnCalendar: Examples Checked With systemd-analyze, and the Persistent Setting Cron Doesn’t Have

A wall calendar and an analog clock above a small rack server

Cron has scheduled Linux jobs for decades with five cryptic fields, and it has one well-known weakness: if the machine is off when a job is due, the job simply doesn’t run. systemd timers fix that and add a few other things, at the cost of a different syntax, OnCalendar=, that looks easy and has corners. Every expression below was checked with systemd-analyze calendar, which prints exactly when a schedule will fire, and the timer behaviors were tested live with systemd 255 (the version in Ubuntu 24.04) running in an isolated container.

Video: tutoriaLinux on YouTube

Two files: the job and the schedule

The service

A timer does not run commands itself. It starts a service unit with the same name. The job:

# /etc/systemd/system/job.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh

The timer

# /etc/systemd/system/job.timer
[Timer]
OnCalendar=*-*-* 03:30:00
Persistent=true

[Install]
WantedBy=timers.target

After systemctl daemon-reload, systemctl enable --now job.timer schedules it. The service is never enabled on its own; the timer starts it when due. The earlier post on systemctl enable versus start covers that distinction.

Seeing the schedule

systemctl list-timers shows every timer with columns for its next run, the time left, its last run, the time since, the timer unit and the service it activates. In the test, the new job.timer appeared at the top of the list with its next run 16 seconds away, above the distribution’s own timers such as apt-daily.timer and logrotate.timer. Adding --all also lists timers that are loaded but not active.

Calendar pages

OnCalendar examples, verified

Reading the format

An OnCalendar= value is DayOfWeek Year-Month-Day Hour:Minute:Second, where any part can be *, a list with commas, a range with .., or a repetition with /. systemd-analyze calendar prints the normalized form and the next times it will fire. Each expression below was run from a base time of Thursday, July 16, 2026, 12:00 UTC, with three iterations:

Expression Normalized form Next three runs
daily *-*-* 00:00:00 Jul 17, 18, 19 at 00:00
weekly Mon *-*-* 00:00:00 Mon Jul 20, Jul 27, Aug 3
hourly *-*-* *:00:00 13:00, 14:00, 15:00
*-*-* 03:30:00 same Jul 17, 18, 19 at 03:30
Mon..Fri 08:00 Mon..Fri *-*-* 08:00:00 Fri Jul 17, Mon Jul 20, Tue Jul 21
Sat,Sun 10:00 Sat,Sun *-*-* 10:00:00 Sat Jul 18, Sun Jul 19, Sat Jul 25
*:0/15 *-*-* *:00/15:00 12:15, 12:30, 12:45
monthly *-*-01 00:00:00 Aug 1, Sep 1, Oct 1
Mon *-*-1..7 09:00 Mon *-*-01..07 09:00:00 Aug 3, Sep 7, Oct 5
*-*~01 *-*~01 00:00:00 Jul 31, Aug 31

Three worth remembering

*:0/15 means every 15 minutes, starting at minute 0. Mon *-*-1..7 09:00 means Monday combined with a day of the month between 1 and 7, which is the first Monday of each month; that is awkward in cron, where the day-of-month and day-of-week fields combine with “or”. And ~ counts from the end of the month: *-*~01 is the last day of every month, which cron cannot express at all.

Longer intervals and one-off dates

The shorthand words go beyond daily and weekly. From the same base time:

Expression Normalized form Next runs
quarterly *-01,04,07,10-01 00:00:00 Oct 1, 2026; Jan 1, Apr 1, 2027
semiannually *-01,07-01 00:00:00 Jan 1, 2027; Jul 1, 2027
*-*-* 00/6:00:00 same 18:00, then 00:00 and 06:00 next day
Fri *-*-13 12:00 Fri *-*-13 12:00:00 Nov 13, 2026; Aug 13, 2027
2026-12-25 07:00 2026-12-25 07:00:00 Dec 25, 2026, once

semiannually had already passed July 1 when checked on July 16, so its next run was half a year away; a job expected “twice a year” might first run much later than assumed. The Friday the 13th line shows how far apart combined conditions can land: the next two were nine months apart. A fully specified date runs once and then never again, which suits a reminder or a one-time migration.

Several schedules on one timer

A timer can carry more than one OnCalendar= line, and it fires at any of them. OnCalendar=Mon..Fri 08:00 plus OnCalendar=Sat,Sun 10:00 gives a weekday time and a weekend time in a single timer, with one service and one log.

Checking before deploying

The normalized form is the useful part. If it doesn’t match what was intended, the mistake shows up before the job runs at the wrong time. An impossible date is reported honestly: *-02-30 normalized fine but printed Next elapse: never. An invalid one is rejected: Mon 25:00 gave Failed to parse calendar specification 'Mon 25:00': Invalid argument.

Time zones and the missing hour

Scheduling in local time

An expression can end with a time zone name. *-*-* 02:30:00 America/New_York was checked from a base time of March 7, 2026, the day before clocks moved forward in the US:

Normalized form: *-*-* 02:30:00 America/New_York
    Next elapse: Mon 2026-03-09 02:30:00 EDT
       (in UTC): Mon 2026-03-09 06:30:00 UTC

The next run was March 9, not March 8. On March 8, 2026, clocks in New York jumped from 2:00 straight to 3:00, so 2:30 never happened that day, and the job skipped it.

The lesson

Jobs scheduled in the hour between 2:00 and 3:00 local time will skip a day each spring. Scheduling in UTC, or at a time outside that hour, avoids the gap. Cron implementations handle the same problem in their own ways; the point is that systemd-analyze calendar makes the behavior visible ahead of time.

Clock

Persistent: catching up on missed runs

What it does

The systemd.timer manual says that with Persistent=true, the time the service last ran is stored on disk, and when the timer is activated, the service is triggered immediately if it would have been triggered at least once while the timer was inactive. It is meant for catching up on runs missed while the system was powered down, and it applies only to OnCalendar= timers.

The test

Two identical timers fired every minute on the minute, one with Persistent=true and one with Persistent=false. Both ran at 05:50:00. Both timers were then stopped at 05:50:07 and left stopped past 05:51:00, then started again at 05:51:22:

--- job (Persistent=true):
ran at 05:50:00
ran at 05:51:22
--- job2 (Persistent=false):
ran at 05:50:00

The persistent timer noticed it had missed 05:51:00 and ran at once. The other waited for the next scheduled minute. A stamp file for the persistent timer appeared in /var/lib/systemd/timers/stamp-job.timer. The manual notes that systemctl clean --what=state removes that file, and suggests doing so before uninstalling a timer, so a later timer with the same name does not inherit an old timestamp. For a nightly backup on a machine that is sometimes off at night, this is the reason to use a timer instead of cron.

Spreading load, accuracy, and boot-relative timers

RandomizedDelaySec

The manual describes RandomizedDelaySec= as delaying the timer by a randomly selected, evenly distributed amount between 0 and the given value. A timer set for 03:00 with RandomizedDelaySec=1h showed its next run as 03:47:11 in list-timers. When many machines share a schedule, such as every server checking for updates at midnight, the random delay keeps them from hitting the same mirror at once. Ubuntu’s own apt-daily.timer was listed at a non-round 09:10:13 for the same reason.

AccuracySec

By default, systemd allows itself some slack. The manual says AccuracySec= defaults to 1min: the timer may elapse anywhere within a one-minute window after the scheduled time, so systemd can batch wakeups and save power. The tests here set AccuracySec=1s so the “every minute” timer fired on the second. For most jobs, the default is fine.

OnBootSec fires at once if boot was long ago

Timers can also count from events instead of the clock: OnBootSec=5min and OnUnitActiveSec=6h together mean five minutes after boot, then six hours after each run. Started in a container that had booted more than five minutes earlier, that timer ran immediately, 15 milliseconds after it was activated. The manual confirms it: a timer configured with OnBootSec= that is already in the past when activated elapses immediately.

Laptop and coffee on a desk

Timers or cron

Where timers win

Missed-run catch-up with Persistent=, schedules cron cannot express such as the last day of the month, built-in random delays, a time-zone-aware schedule per job, and logging: each run’s output goes to the journal under the service name, journalctl -u job.service, with its exit status. A timer whose service fails shows as failed in systemctl status.

Where cron is simpler

One line in a crontab against two unit files. For a quick personal job on a machine that is always on, cron is still fine. Either way, the job runs without a login shell’s environment; the earlier post on systemd environment variables explains exactly what a timer-started service gets.

Sources

  • systemd.timer(5), Linux manual page (man7.org): https://man7.org/linux/man-pages/man5/systemd.timer.5.html

710 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *