Search this blog:

Words and works.

Using cron with Drupal

Several of Drupal's modules, such as Search and Aggregator, require intervention in order to be kept up-to-date. This intervention can be automated by using some sort of scheduler. On Linux systems the cron utility can be used for this purpose.

Drupal provides a php script named cron.php which lives in the root of your Drupal site by default. When the cron.php script is executed, it will trigger those tasks that need to be performed. We can use cron to cause the cron.php script to be executed on a consistent schedule.

Here's what we did on our MandrakeLinux 10.1 system:

  1. Create a file containing the following text:
    #!/bin/sh
    wget -O - -q http://www.yourdomain.com/cron.php
    (Replace "yourdomain" with your actual domain name, of course.) We named the file drupal-cron.
  2. Make the file executable: chmod +x drupal-cron
  3. Put the file in the appropriate cron subdirectory. We placed the file in /etc/cron.hourly. This causes cron to execute the drupal-cron file once every hour.
    Other Linux distros may require that you use the crontab command to schedule the wget task. Examples of using the crontab command are available here.

That's it!

Tags: cron, drupal, linux | Permalink

© 2009 Evenhouse Consulting, Inc.

A Django site.