The Free Encyclopedia

Cron and Scheduling

Revision as of Jun 28, 2026 21:08 by albert.

Need something to run nightly, hourly, or every five minutes? cron (and its modern cousin, systemd timers) handle scheduled jobs.

Cron — the classic

crontab -e        # edit your jobs
crontab -l        # list them
# ┌ min ┌ hour ┌ day ┌ month ┌ weekday   command
  0     3      *     *        *           /home/me/backup.sh   # 3am daily
  */5   *      *     *        *           /home/me/check.sh    # every 5 min

Use crontab.guru to decode the five fields.

systemd timers — the modern way

More powerful (logging, dependencies, missed-run catch-up). A .timer triggers a matching .service:

# backup.timer
[Timer]
OnCalendar=*-*-* 03:00:00
Persistent=true        # run if the machine was off at the scheduled time

[Install]
WantedBy=timers.target
cron systemd timer
Simple, everywhere Logs via journald, catch-up, deps
One line Two unit files

Gotcha: cron runs with a minimal environment — no fancy PATH, no profile. Use absolute paths and set vars explicitly, or your job "works in the shell but not in cron."

Related: Understanding systemd · Shell Scripting Basics · Encrypted Backups with restic