Skip to main content

Cron is a job scheduler that allows users to run commands periodically.

Cron is a daemon that runs periodic scheduled jobs.

Use the crontab command to edit the table of scheduled jobs.

Use to schedule a job for one execution only at a specific date.

Common pitfalls

If a command works when you type it in a terminal but not from a crontab, here are some common reasons:

  • Cron provides a limited environment, e.g., a minimal $PATH.

    • Try adding this entry to your crontab to see what cron's environment is:

      * * * * * { date; pwd; echo "env:"; env; echo "set:"; set; } > ~/cron.env 
      
  • Cron uses /bin/sh, which may not be the shell you normally use.

  • Cron treats the % character specially (it is turned into a newline in the command).

    • This will affect the date command especially:

      * * * * * date "+%F %T"     # bad: cron sees `date "+`
      * * * * * date "+\%F \%T"   # good
      

Further reading