Video tutorials and Online Training
Unlimited Access
Video Tutorials
Video Available as Flash

Bookmark Us

Bookmark Website 
Bookmark Page 

User login

Recent comments

Navigation

Dynamically execute all Drupal cron jobs for an entire server

You may have a lot of Drupal sites installed on the same server. Instead of creating a cron job for each individual site, you could write a script like this to loop through your sites and execute each cron job automatically. Here's the script I created using PHP, lynx, and find:

#!/usr/bin/php

<?php
// define where vhosts exist
$sitesDir = '/var/www/vhosts';

// change dir
chdir($sitesDir);

// get a list of directories
// Pipe 1: get all directories
// Pipe 2: remove "./" from beginning of each line
// Pipe 3: remove "."
$command = "find . -maxdepth 1 -type d | sed 's/^\.\///' | sed 's/^\.$//'";

// execute command
$dirs = `$command`;

// convert string into array
$dirs = explode("\n", trim($dirs));

// loop through directories
foreach ($dirs as $d)
{
   
// ensure cron.php exists
   
if (file_exists($sitesDir . '/' . $d . '/httpdocs/cron.php'))
    {
       
$command = "/usr/bin/lynx -source http://$d/cron.php > /dev/null 2>&1";
       
$output = `$command`;
    }
}
?>

I then added the following cron job to root:

#min    hour    dMonth  month   dWeek   command
*/5     *       *       *       *       ~/scripts/drupal-crons.php

No comments

Add your comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.

Videos Search