systemd timers vs cron: when to use which
Compare systemd timers and cron jobs for task scheduling — features, logging, dependencies, and migration path.
systemd timers vs cron: when to use which
systemd timers and cron both schedule recurring tasks on Linux, but they differ in logging, dependency management, and configuration style.
How Cron Schedules Tasks
Cron uses the
crontab file format to schedule commands. Each line in a crontab defines a schedule (minute, hour, day, month, weekday) and the command to run. Cron has no built-in dependency management — it runs commands regardless of what other services are doing. Cron captures output via email (if configured) or discards it.
How systemd Timers Schedule Tasks
systemd timers use two unit files — a
.timer file (defining the schedule) and a
.service file (defining the task). Timers support both calendar-based scheduling (
OnCalendar=) and boot-relative scheduling (
OnBootSec=). systemd logs all timer activity to the journal, manages dependencies between timer-activated services and other units, and supports randomized delays to stagger execution.
Feature Comparison: systemd Timers vs Cron
| Feature | Cron | systemd Timers |
|---|---|---|
| Logging | Email or manual redirection to file | Automatic journal integration via
journalctl -u |
| Dependencies | None — runs commands independently | Full systemd dependency management with
After=,
Requires= |
| Missed executions | Lost if system was off at scheduled time (unless anacron) | Persistent=true runs missed tasks on next boot |
| Randomized delay | Not supported | RandomizedDelaySec= staggers execution across systems |
| Resource limits | Not supported | Full cgroup integration (
MemoryMax=,
CPUQuota=) |
| Configuration format | Single-line crontab entries | Two YAML-like unit files (
.timer+
.service) |
| Listing scheduled jobs | crontab -l (per-user only) | systemctl list-timers (system-wide view) |
When to Use Cron
Cron is appropriate for simple, single-line commands on systems where cron is already established and the task has no dependencies on other services. Cron is also the default on older distributions that do not run systemd.
When to Use systemd Timers
systemd timers are the better choice when tasks depend on other services (e.g., a backup that requires a database to be running), when logging to the journal is preferred over email, when resource limits should apply to scheduled tasks, or when tasks must run after missed schedules.
For new scheduled tasks on systemd-based distributions, systemd timers provide better observability and control than cron. For migrating existing cron jobs, see How to replace a cron job with a systemd timer.