“cron” is a way of scheduling periodic jobs in Linux or Unix like systems.

Usage

See [1] for more details.

  • To set the cron table: crontab -e.
  • To see the scheduled jobs: crontab -l.
  • To see the cron logs: grep CRON /var/log/syslog [3].

Format and Examples

*   *   *   *   *  sh /path/to/script/script.sh
|   |   |   |   |  |
|   |   |   |   |  Command or Script to Execute
|   |   |   |   |
|   |   |   |   Day of the Week(0-6)
|   |   |   |
|   |   |   Month of the Year(1-12)
|   |   |
|   |   Day of the Month(1-31)
|   |
|   Hour(0-23)
|
Min(0-59)
Value Meaning
5 8 * * * 8:05 every day
0 15 * * 6 15:00 on Saturday
0 22 * * 1-5 22:00 every weekday

See [2] for more examples.

Misc

  • Avoid backslash \ in cron command [4].
  • The time zone used by cron might default to UTC, use date command to check. To set local time zone: sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime [5].

References

  1. https://www.freecodecamp.org/news/cron-jobs-in-linux/
  2. https://crontab.guru/
  3. https://askubuntu.com/questions/56683/where-is-the-cron-crontab-log
  4. https://unix.stackexchange.com/questions/605842
  5. https://serverfault.com/questions/791713