Scheduling: cron & at
cron - recurring jobs
A crontab line has five time fields then the command:
┌ minute (0-59)
│ ┌ hour (0-23)
│ │ ┌ day of month (1-31)
│ │ │ ┌ month (1-12)
│ │ │ │ ┌ day of week (0-7, 0 & 7 = Sunday)
│ │ │ │ │
* * * * * /path/to/command
| Command | Action |
|---|---|
crontab -e | Edit your crontab |
crontab -l | List |
crontab -r | Remove |
System-wide: /etc/crontab, /etc/cron.d/, and the /etc/cron.{hourly,daily,weekly,monthly}/ directories.
Examples:
0 2 * * * backup.sh # every day at 02:00
*/15 * * * * check.sh # every 15 minutes
0 9 * * 1-5 report.sh # 09:00 on weekdays
at - one-off jobs
$ echo 'reboot' | at 03:00
$ atq # list pending
$ atrm 3 # remove job 3
Exam tip:systemd timersare the modern alternative to cron (systemctl list-timers).