Multi-site Cron Bash Script

Last modified: May 8, 2009 - 15:34

A quick bash script to run cron for multiple sites:

#!/bin/bash

## Define your websites in an array
sites=(example.com example2.com example3.com)

len=${#sites[*]}
for((i=0; i<$len; i++)); do
        wget -q http://${sites[${i}]}/cron.php
        # You may remove (or comment) the following line if you
        # wish to retain the downloaded file.
        rm cron.php
done

minor glitch in here

jan.n - May 6, 2009 - 10:37

len=${#sites} only returns the length of the first element of the array.
Change it to len=${#sites[*]} to return the total number of elements in the array.

Jan

PS: The array can also contain slashes, in case your drupal installation is not in the server root.
PPS: (edit) if you change your wget command to include -O - (that is no zero, it's an O) you have no files to delete:
wget -O - -q -t 1 http://...

THX for correcting

jan.n - May 18, 2009 - 11:25

THX for correcting

 
 

Drupal is a registered trademark of Dries Buytaert.