This chapter follows Booting Linux and systemd.
Backups, certificate renewal, and report generation need to run on a clock. Debian ships cron, anacron, systemd timers, and at for different scheduling shapes. Picking the right one avoids duplicate jobs, missed runs on laptops, and services that start without logging.
Cron and crontab syntax
cron wakes every minute and runs entries whose time fields match. System-wide jobs live in /etc/cron.d/ and /etc/cron.{hourly,daily,weekly,monthly}/. Per-user tables come from crontab -e.
A crontab line has five time fields (minute, hour, day of month, month, weekday) plus a command:
# minute hour dom month dow command0 3 * * * /usr/local/bin/backup.shcron assumes the machine is on at the scheduled minute. A server that runs 24/7 is the sweet spot. Output may be mailed to the user (if mail is configured) or lost—redirect logs explicitly in scripts.
List your user crontab:
crontab -lAnacron for intermittent uptime
anacron runs daily/weekly/monthly jobs when the system was off at the scheduled cron time—common on laptops. Debian’s /etc/anacrontab defines delays and job scripts under /etc/cron.daily and friends that anacron triggers after boot.
Use anacron-friendly paths when jobs must eventually run but not at an exact minute. Do not duplicate the same script in both strict cron and anacron without meaning to.
systemd timers
systemd timers pair with .service units: the timer unit schedules activation, the service unit runs the work. Timers integrate with journald, dependencies, and systemctl lifecycle—natural on systemd-first Debian.
Example layout (conceptual):
[Timer]OnCalendar=*-*-* 03:00:00Persistent=true
[Install]WantedBy=timers.targetsystemctl list-timers --allsystemctl enable --now backup.timerPersistent=true catches up missed runs after downtime—similar spirit to anacron. Prefer timers when the job is already a managed service, needs ordering with other units, or should log to the journal.
at for one-shot delays
at queues a single command at a future time:
echo "/usr/local/bin/report.sh" | at 09:00 tomorrowatqatrm 3Use at for ad hoc deferral, not recurring schedules. Access may be restricted via /etc/at.allow and /etc/at.deny.
Choosing a scheduler on Debian
| Need | Reasonable choice |
|---|---|
| Exact minute on always-on server | cron or systemd timer |
| Daily script, laptop sleeps often | anacron paths or timer with Persistent= |
| Service with logs and dependencies | systemd timer + service |
| Run once later today | at |
Avoid running the same maintenance script from a user crontab and a systemd timer. Document the owner in /etc/cron.d/README or unit descriptions for the next administrator.
Storage and devices come next: Linux filesystems explains how mounted trees and virtual filesystems expose the running kernel to tools you already use.
The next chapter is Linux filesystems.
Check your understanding
Question 1 of 5
0 of 5 checked