systemd Timers
A timer is a unit that starts another unit on a schedule. cron & systemd showed the idea next to crontab; on servers timers are usually the better tool, because the job becomes a real service: logged in the journal, visible in systemctl, protected by the same sandboxing and resource limits, and never started twice at once.
A timer and its service
A timer backup.timer starts backup.service (same name, different suffix) unless it says Unit=:
# /etc/systemd/system/backup.service
[Unit]
Description=Nightly backup of /srv
[Service]
Type=oneshot
User=backup
ExecStart=/usr/local/bin/backup-srv# /etc/systemd/system/backup.timer
[Unit]
Description=Run the nightly backup
[Timer]
OnCalendar=*-*-* 02:30:00
RandomizedDelaySec=15min
Persistent=true
[Install]
WantedBy=timers.targetYou enable the timer, not the service: systemctl enable --now backup.timer. The service has no [Install] section because nothing but the timer should start it.
| Key | Meaning |
|---|---|
OnCalendar= |
wall-clock schedule (calendar expression, below) |
OnBootSec=, OnStartupSec= |
a delay after boot / after systemd started |
OnUnitActiveSec=, OnUnitInactiveSec= |
a delay after the service last started / finished: "every 10 minutes after the last run" |
Persistent=true |
if the machine was off at the scheduled time, run once at the next boot (only for OnCalendar=) |
RandomizedDelaySec= |
add a random delay up to this value, so 500 servers don't hit the backup target at the same second |
AccuracySec= |
how much systemd may shift the start to batch wake-ups (default 1 min) |
Calendar expressions
The format is DayOfWeek Year-Month-Day Hour:Minute:Second, where any part can be *, a list (Mon,Thu), a range (Mon..Fri, 1..5) or a repetition (*:0/15 = every 15 minutes). Shorthands such as daily, weekly, hourly exist too. Never guess what an expression means: systemd-analyze calendar normalises it and shows the next run times. The --base-time pins "now" to a fixed moment (Thursday 15 January 2026, 10:00 UTC) so the answers below don't change:
for spec in "daily" "Mon *-*-* 02:00:00" "Mon..Fri 09..17:00" "*:0/15" "*-*-01 03:00:00"; do
systemd-analyze calendar --base-time="2026-01-15 10:00:00 UTC" --iterations=2 "$spec" | grep -v 'From now'
echo
done Original form: daily
Normalized form: *-*-* 00:00:00
Next elapse: Fri 2026-01-16 00:00:00 UTC
Iteration #2: Sat 2026-01-17 00:00:00 UTC
Normalized form: Mon *-*-* 02:00:00
Next elapse: Mon 2026-01-19 02:00:00 UTC
Iteration #2: Mon 2026-01-26 02:00:00 UTC
Original form: Mon..Fri 09..17:00
Normalized form: Mon..Fri *-*-* 09..17:00:00
Next elapse: Thu 2026-01-15 11:00:00 UTC
Iteration #2: Thu 2026-01-15 12:00:00 UTC
Original form: *:0/15
Normalized form: *-*-* *:00/15:00
Next elapse: Thu 2026-01-15 10:15:00 UTC
Iteration #2: Thu 2026-01-15 10:30:00 UTC
Normalized form: *-*-01 03:00:00
Next elapse: Sun 2026-02-01 03:00:00 UTC
Iteration #2: Sun 2026-03-01 03:00:00 UTC
Mon..Fri 09..17:00 runs on the hour from 09:00 to 17:00 on weekdays (the next one is 11:00, because 10:00 is "now", not the future); *-*-01 is the first of every month. systemd's canonical range separator is .., though it also accepts Mon-Fri. Mistakes are reported, not guessed at, and the most common one is pasting a cron line:
for spec in "0 2 * * *" "Mon *-*-* 25:00" "*-02-30 00:00:00" "Fri *-*-13 00:00:00"; do
echo "== $spec"
systemd-analyze calendar --base-time="2026-01-15 10:00:00 UTC" "$spec" 2>&1 | grep -E 'Failed|Next elapse'
done== 0 2 * * *
Failed to parse calendar specification '0 2 * * *': Invalid argument
== Mon *-*-* 25:00
Failed to parse calendar specification 'Mon *-*-* 25:00': Invalid argument
== *-02-30 00:00:00
Next elapse: never
== Fri *-*-13 00:00:00
Next elapse: Fri 2026-02-13 00:00:00 UTC
The 30th of February is a valid expression that never elapses: worth catching before you wait a year for a backup. And "Friday the 13th" shows that day-of-week and date are combined with AND (cron combines them with OR).
Time spans
Durations in unit files (RandomizedDelaySec=15min, OnBootSec=90s, TimeoutStopSec=1min 30s) use systemd's time-span syntax. systemd-analyze timespan shows how it is parsed, in microseconds. A bare number is read as seconds in most settings:
systemd-analyze timespan "15min" "1h 30min" "2d" "90" | grep -E 'Original|μs|Human'Original: 15min
μs: 900000000
Human: 15min
Original: 1h 30min
μs: 5400000000
Human: 1h 30min
Original: 2d
μs: 172800000000
Human: 2d
Original: 90
μs: 90000000
Human: 1min 30s
Checking the pair before installing
systemd-analyze verify on the timer also loads and checks the service it triggers, from the same directory. It does not complain about a timer whose service is missing, so check that yourself:
cat > report.service <<'EOF'
[Unit]
Description=Weekly disk report
[Service]
Type=oneshot
ExecStart=/usr/bin/df -h /
EOF
cat > report.timer <<'EOF'
[Unit]
Description=Weekly disk report
[Timer]
OnCalendar=Mon *-*-* 07:00:00
Persistent=true
[Install]
WantedBy=timers.target
EOF
printf '[Timer]\nOnCalendar=daily\n[Install]\nWantedBy=timers.target\n' > orphan.timer
for t in *.timer; do
systemd-analyze verify "./$t" && echo "$t: verify OK"
svc=$(sed -n 's/^Unit=//p' "$t"); svc=${svc:-${t%.timer}.service}
[ -f "$svc" ] || echo "$t: ERROR, it would start $svc, which does not exist"
doneorphan.timer: verify OK
orphan.timer: ERROR, it would start orphan.service, which does not exist
report.timer: verify OK
On a server, a timer pointing at a missing service fails at the first elapse, typically at night.
Timers on a live server
$ systemctl list-timers --all
NEXT LEFT LAST PASSED UNIT ACTIVATES
Thu 2026-01-15 10:15:00 UTC 14min Thu 2026-01-15 10:00:01 UTC 59s ago sysstat-collect.timer sysstat-collect.service
Fri 2026-01-16 00:00:00 UTC 13h Thu 2026-01-15 00:00:04 UTC 10h ago logrotate.timer logrotate.service
Fri 2026-01-16 02:41:17 UTC 16h Thu 2026-01-15 02:37:52 UTC 7h ago backup.timer backup.service
3 timers listed.
$ sudo systemctl start backup.service # run the job now, outside the schedule
$ journalctl -u backup.service --since today # what did the last runs print?Notice the NEXT time of backup.timer: 02:41:17, not 02:30:00, because of RandomizedDelaySec=15min. Starting the service by hand is the way to test a job; it runs with exactly the user, environment and sandbox the timer will use, which is the step cron jobs never had.
For one-off delayed jobs, systemd-run creates a transient timer without writing files: sudo systemd-run --on-active=30min /usr/local/bin/cleanup.
Test yourself
Which unit do you enable for a scheduled job?
- The .service
- The .timer
- Both
- timers.target
The server was powered off at 02:30, when OnCalendar=*-*-* 02:30:00 should have fired. What makes the job run at the next boot?
- AccuracySec=1s
- Persistent=true
- OnBootSec=0
- RandomizedDelaySec=0
Why does systemd-analyze calendar "0 2 * * *" fail?
- The hour is out of range
- It is a cron line; systemd's format is
DayOfWeek Year-Month-Day Hour:Minute:Second, here*-*-* 02:00:00 - Timers can't run at 02:00
- It needs
--base-time