Cron

From Support

Jump to: navigation, search

Cron is a periodic task scheduler for linux and unix. Aside from having one of the most awesome names for a daemon, it is also fantastically useful.

Cron runs in the background all the time and at certain appointed times performs jobs as defined by different users. If you want to download your favourite podcast and you know that it is released at 11 o'clock every wednesday, you can set cron to download it at 11:01 every week. This is even more useful for administrative tasks like making sure that a system is up to date.

Cron is the daemon that runs in the background but to control cron, every user has their own crontab. Crontab is a file that tells cron what to do.

The crontab file is very simple, 6 columns. The first 5 specify when you want things to happen and the last one specifies what you want to happen.

  1. m h dom mon dow command

The m column specifies what minute you want the command to be run. The h column specifies what hour you want the command to be run. The dom column specifies what day of the month you want the command to be run. The mon column specifies what month you want the command to be run. The dow column specifies what day of the week you want the command to be run. The command column specifies what command you want to be run.

The values that can be put into the table are as follows:

field allowed values


--------------

minute 0-59 hour 0-23 day of month 1-31 month 1-12 day of week 0-7 (0 or 7 is Sun, or use names)

For example, if you wanted to run $command every Thursday, the line in your crontab would look like this:

0 12 * * thu $command

If you want to run $command every week day at 9 in the morning

0 9 * * 1-5 $command

You can use - to indicate ranges of times.

Personal tools