Community Documentation

Multisite with cron-curl.sh

Last updated March 7, 2013. Created by bb37 on February 28, 2008.
Edited by 2020media, add1sun. Log in to edit this page.

I have domain1.com hosted as the primary domain with domain2.com "parked" at domain1.com. My public_html/sites folder looks like this:

sites/all
sites/default
sites/domain2

My webhost (an Apache server running Cpanel 11) blocks user access to lynx or wget, so the normal recommendations for setting up a crontab were not working for me. However, I discovered a suggestion in http://drupal.org/cron to try the cron-curl.sh script that ships with Drupal in the "scripts" folder. I edited cron-curl.sh so that it includes the following line:

curl --silent --compressed http://domain1.com/cron.php

And then I set up a crontab that looks like this:

*/2 * * * * /home/webhostaccountname/public_html/scripts/cron-curl.sh

After remembering to set the file permissions on cron-curl.sh so that it could be executed, the cron job worked perfectly. The "*/2" executes the crontab every other minute for testing purposes only.

So, then I went back into cron-curl.sh and added the following line:

curl --silent --compressed http://domain2.com/cron.php

Again, success! I'm watching the logs for both domain1.com and domain2.com. Cron jobs are being executed every 2 minutes for both domains.

Comments

cron-curl.sh How To Case

Here I detail my battle and ultimate victory in setting up cronjobs to run for live multiple drupal
websites. I found it very arduous to get cronjobs to work on my webhost. Also, drupal guide pages
and support pages were much lacking. Even the scripts that come with drupal were not complete
enough as it seems a 'user-agent' must be specified for the script to work.

Errors returned from cronjob run attempts:

The gist of the problem and solution that worked for that was inappropriate file encoding.
Windows will make the encoding of the .sh files unusable for the Unix which handles the files if
the file is edited and saved on your local Windows computer. And you can't do without changing
example.com in the drupal scripts! You can convert to correct Unix form with the dos2unix online tool.

Tip: a great helper for checking for the proper file format is to 'view' the file in cPanel and look for the
detected type right at the top of the page. You want to see "Bourne shell script text executable "
for your cron-curl.sh file.

  • permission denied

You can use filemanager in your hosts cPanel to check and set permissions with a right click on
a file or directory. Files and directories must have sufficient permissions. In this case the scripts
directory, the cron-curl.sh file, and perhaps the cron.php file needed to be reset from 644 to 755.


Here is the curl script that worked:
  curl --silent --compressed -A "Mozilla/5.0" http://works1.com/cron.php
  curl --silent --compressed -A "Mozilla/5.0" http://works2.com/cron.php
 
 

Here is the cron line that runs it correctly once every day at midnight:
  0 0  * * * /home/webhostaccountname/public_html/scripts/cron-curl.sh

Some good references:

nobody click here