Drupal Cron Jobs - How to Setup Cron in Drupal

Submitted by james on

Ever get the status message "cron has not run", from the Drupal status page? In this video I show you how to setup a cron job that fires "www.yoursite.com/cron.php" every hour, so you don't have to run cron manually ever again. Drupal cron jobs made easy!

Drupal Cron Jobs - Notes

When you run crontab -e, you may need to be logged in as the administrator user of your web server.

Cron can be setup to run a command more or less than once an hour. In the video we add the following line to our crontab file to run cron.php at the start of every hour.

0 * * * * /usr/bin/wget -O - -q -t 1 http://www.yoursite.com/cron.php

The 5 characters separated by spaces controls when cron will run the command on the right. Lets break it down with some ascii art:

* * * * * command
| | | | |
| | | | |_day of week (0-6) where Sunday is 0
| | | |
| | | |_month (1-12)
| | |
| | |_day of month (1-31)
| |
| |_hour (0-23)
|
|_minute (0-59)

So say you wanted to run cron.php once every day. The following line would run your drupal cron job every night at midnight:

0 0 * * * /usr/bin/wget -O - -q -t 1 http://www.yoursite.com/cron.php

The next line would run the drupal cron job every day at 2:30pm, or 14:30 military time:

30 14 * * * /usr/bin/wget -O - -q -t 1 http://www.yoursite.com/cron.php

Lets run cron every Sunday and Wednesday at 3am:

0 3 * * 0,3 /usr/bin/wget -O - -q -t 1 http://www.yoursite.com/cron.php

This allows for lots of flexibility in when you'd like to run your drupal cron job.

Article Categories