Crontab cheat sheet

The five fields, the shortcuts and the two mistakes everybody makes.

SNP 051 #941 Filed cmd linux

shell
crontab -e
shell
# ┌ minute (0-59)
# │ ┌ hour (0-23)
# │ │ ┌ day of month (1-31)
# │ │ │ ┌ month (1-12)
# │ │ │ │ ┌ day of week (0-6, Sunday is 0)
# │ │ │ │ │
  0 3 * * *   /home/ian/backup.sh
  */15 * * * * /home/ian/check.sh
  0 9 * * 1-5 /home/ian/standup.sh

The shortcuts @hourly, @daily, @weekly, @monthly and @reboot work in place of the five fields.

The two mistakes: cron runs with a tiny PATH, so use full paths to your programs, and it has no idea what you see in your terminal, so send the output somewhere:

shell
0 3 * * * /home/ian/backup.sh >> /home/ian/backup.log 2>&1