crontab
run a command on a schedulecrontab manages your table of scheduled jobs. Each line is five time fields followed by a command, and the cron service runs the command whenever the clock matches — every night, every Monday, every five minutes.
The five fields, in order: minute, hour, day of month, month, day of week.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
A comment kept as a reminder: minute, hour, day of month, month, day of week, then the command.
Minute 0, hour 2, and stars for the rest: any day, any month, any weekday.
*/5 in the minute field means "every fifth minute". The output is thrown away so cron does not try to mail it.
Day of week 1 is Monday. Output and errors are appended to a log, which is how you find out why a job failed.
Switches
A switch changes how the command behaves. These are the ones used day to day; man crontab lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
-e- Edit your crontab.
-l- List your crontab.
-r- Remove your whole crontab — without asking.
-u USER- Work on another user’s crontab. Needs root.
-i- With -r, ask for confirmation first.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
crontab -eEdits your schedule. It is installed when you save and quit.
sudo crontab -l -u www-dataLists another user’s jobs.
@reboot /home/user/start.shA crontab line that runs once each time the machine starts.
systemctl list-timersLists systemd timers — the modern alternative to cron.
In cybersecurity
A scheduled job is a command that runs with nobody watching.
A line added to a crontab runs for ever. Reviewing every user’s crontab and /etc/cron.* is a standard step in checking a suspect machine.
If root’s crontab runs a script that another user can edit, that user can run anything as root. Check the permissions of every script cron calls.
Cron runs with a short PATH. A bare command name may not be found — or may find a different program from the one you meant.