Linux Command Reference ยท Systemd and Logging (Read-Only)
systemd timer units
Schedule jobs with systemd timers instead of cron: .timer and .service pairs, OnCalendar syntax, OnBootSec, Persistent=, and systemctl list-timers.
A timer unit (name.timer) activates another unit, normally name.service, at certain times. It is systemd's replacement for cron jobs: schedules can be calendar-based or relative to boot, missed runs can be caught up after downtime, and each run is a normal service with logs in the journal, resource limits and dependencies.
You always write two files: a service that does the work (often Type=oneshot) and a timer that triggers it. Then you enable the timer, not the service. The sandbox has no systemd, so this page is read-only; the examples build the files and decode OnCalendar expressions with plain shell.
# backup.timer [Timer] OnCalendar=*-*-* 02:30:00 Persistent=true [Install] WantedBy=timers.target
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
# [Timer] section directives
OnCalendar=EXPRESSION
OnBootSec=TIME OnStartupSec=TIME
OnUnitActiveSec=TIME OnUnitInactiveSec=TIME
OnActiveSec=TIME
AccuracySec=TIME RandomizedDelaySec=TIME Persistent=BOOL
Unit=other.service WakeSystem=BOOL
| Name | Description |
|---|---|
OnCalendar= |
Wall-clock schedule, e.g. *-*-* 02:30:00 (daily at 02:30), Mon..Fri 09:00, *:0/15 (every 15 minutes), or shortcuts hourly, daily, weekly, monthly, yearly. |
OnBootSec= |
Time after the machine booted, e.g. 15min. |
OnStartupSec= |
Time after the service manager started (differs from boot for --user timers). |
OnActiveSec= |
Time after the timer itself was activated. |
OnUnitActiveSec= |
Time after the triggered unit last started: repeat every N after each run. |
OnUnitInactiveSec= |
Time after the triggered unit last finished. |
Persistent= |
With OnCalendar=, run once at startup if a scheduled run was missed while the machine was off. |
RandomizedDelaySec= |
Add a random delay up to this value to spread load across many machines. |
AccuracySec= |
Allowed slack (default 1 min) so wakeups can be batched; set 1s for precision. |
Unit= |
Unit to trigger if it is not the one with the same base name. |
Returns / checking: systemd-analyze calendar "EXPR" prints the normalized form and the next elapse times; systemctl list-timers shows NEXT, LEFT, LAST and PASSED for each timer.
Errors and edge cases: an invalid expression makes the timer fail to load ("Failed to parse calendar specification"). Time values accept s, min, h, d, w, month, y and can be combined (1h 30min).
Usage notes
- Enable the timer, not the service.
systemctl enable --now backup.timer; the service has no[Install]section and runs only when triggered. - Edit, then reload. After changing a
.timerfile runsystemctl daemon-reloadand restart the timer. Persistent=truestores the last run time under/var/lib/systemd/timers/; use it for daily jobs on laptops that are often off at 02:30.- Time zones.
OnCalendar=uses the system zone unless you append one, such asUTC; daylight-saving shifts can skip or double a local time. - Overlap. If the service is still running when the timer fires again, systemd does not start a second copy; the trigger is skipped.
- Compared with cron. Timers log to the journal, support dependencies and sandboxing, and can catch up after downtime, but need two files and are more verbose. See
crontabfor the classic way. - User timers:
systemctl --userwith files in~/.config/systemd/user/run as you; addloginctl enable-lingerto keep them going after logout. - Test the schedule without waiting: run the service by hand with
systemctl start backup.service.