wiki:faq/cron-job

Version 5 (modified by Jamie McClelland, 16 years ago) (diff)

--

How do I add a cron job?

A cron job is a command that runs repeatedly at a given time. Often, cron jobs are set to run tasks like updating your web site statistics once an hour, or backup your data every day, or access your Drupal installation's cron.php script on a regular basis.

To set a cron job, you will need to access your server using a secure shell program. Please refer to our secure shell page for information about how to run secure shell on your computer.

Once you have connected via secure shell to your primary server, you can create a cron job by typing:

crontab -e

After typing this command, a text editor program will open, prompting you to enter your crontab information.

The crontab syntax is a series of space separated numbers or asterisks, followed by the command you want to run. For example:

5 * * * * wget -q -O- http://mayfirst.org/cron.php >/dev/null

The first five items (in this case: 5 * * * *) refers to when the cron job should be run. The columns are: minute, hour, day of month, month, day of week. An asterisk means always run. So, in the example above, it says, run at 5 minutes after the hour, every hour, every day, every month and every day of the week. Similarly, typing (5 8 * * *) would mean to run at 8:05 every day.

Everything after the numbers and asterisks is the command to be run. In this example, it means: access the http://mayfirst.org/cron.php script.