Both cron and systemd timers can schedule recurring tasks on Linux. Cron is ubiquitous and simple; systemd timers offer richer reliability, dependencies, and logging. Here's how to choose.
Overview
Cron executes commands based on a 5-field time expression in a minimal environment. systemd timers use unit files, enabling dependency management, standardized logging via journalctl, and calendar-based scheduling.
Quick Examples
0 2 * * * /usr/local/bin/backup.sh[Unit] Description=Nightly backup [Service] Type=oneshot ExecStart=/usr/local/bin/backup.sh # backup.timer [Unit] Description=Run backup daily [Timer] OnCalendar=daily Persistent=true [Install] WantedBy=timers.targetKey Differences
Cron
- Simple 5-field expression
- Minimal environment (PATH, SHELL)
- Logging via syslog (distribution-specific)
- No native dependency management
systemd Timers
- Calendar syntax (e.g.,
OnCalendar=Mon..Fri 09:00) - Dependencies and ordering (
After=,Requires=) - Centralized logs (
journalctl -u) - Persistence across downtime (
Persistent=true)
When to Choose Cron
- Portable scripts across many Unix-like systems
- Ultra-lightweight scheduling with no service dependencies
- Human-friendly, copy/paste cron expressions
When to Choose systemd Timers
- Need structured logs and
journalctlvisibility - Require dependency ordering or network availability
- Want missed runs to execute on boot (
Persistent=true)
Migration Tips
- Start with mission-critical jobs to benefit from logging and persistence.
- Mirror your cron schedule using
OnCalendar(e.g.,daily,weekly, or explicit weekdays). - Create a oneshot
.servicefile for the job and a matching.timer. - Enable and start the timer:
systemctl enable --now backup.timer
Helpful Tools
Use the Visual Builder to design a schedule, the Validator to check syntax, and the Timezone Converter to preview runs across time zones.