Drupal – Add Task to the Drupal Cron Job

Drupal has a cron.php at the root directory. you can run the this cron job by either entering the http://<drupal_root>/cron.php in browser or running it directly in the Drupal status report.

The default Drupal cron job cleans up log files and checks for Drupal and modules updates. If you want this cron job to be run at a regular interval, just edit the crontab by the following command.

  • crontab -e

 

and add one of the following lines with you desired interval. (45 mins in the following example)

45 * * * *  /usr/bin/lynx -source http://<drupal_root>/cron.php
45 * * * * /usr/bin/wget -O - -q -t 1 http://<drupal_root>/cron.php
45 * * * * curl --silent --compressed http://<drupal_root>/cron.php 

 

Drupal also provides the hook_cron() function which you can add more tasks to the Drupal cron job. Create a custom module and add the following function.

function custom_cron() {
  print 'I am executed with the Drupal cron job';
}

 

Open a browser and run the cron job by entering the following url

 

See what you get.

Done =)

Reference: Drupal Documentation – Configuring cron jobs

One thought on “Drupal – Add Task to the Drupal Cron Job”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.