Hello everyone. I am after some help with CRON. All i want it to do is automatically run the http://website.com/cron.php every 45minutes or so.

I had put this line into the Crontab -e:

45 * * * * /usr/bin/wget -O - -q -t 1 http://www.website.com/cron.php

But this is not working from what i can see as nothing is being put into the Watchdog log.

So i gave Poormanscron a go. Again, i set the time interval to 45 minutes, and again nothing.

Where am i going wrong? Please help.

Comments

GavinC’s picture

i have just run the command

/usr/bin/wget -o - -q -t 1 http://yellow-zebra.co.uk/cron.php

and it worked in the command line. Why wont it work in Crontab -e?

arh1’s picture

shouldn't the cron job call scripts/cron-lynx.sh or scripts/cron-curl.sh ? that's what all of mine do... not sure of the pros/cons of those scripts vs wget.

GavinC’s picture

Do you have the full command that is need please?

arh1’s picture

00 4 * * * /path/to/drupal/scripts/cron-lynx.sh

and of course be sure to edit cron-lynx.sh to use your domain name.

also be sure that the web server user is able to execute the script. (i had to chmod 755.)

-Anti-’s picture

I would note two things:

1)
There is a 'bug' in Drupal6.8 which affects some hosts. In /includes/bootstrap.inc Line 279:

function drupal_valid_http_host() {
  $_SERVER['HTTP_HOST'] = strtolower($_SERVER['HTTP_HOST']);
  return preg_match('/^\[?(?:[a-z0-9-:\]_]+\.?)+$/', $_SERVER['HTTP_HOST']);
}

This new part, which increases security, does not allow a blank http_host.
If it is blank, one repercussion is that cron fails without error.
You might need to change this part to:

function drupal_valid_http_host() {
if (empty($_SERVER['HTTP_HOST'])) return true; // EDIT: Added this line to fix bug
  $_SERVER['HTTP_HOST'] = strtolower($_SERVER['HTTP_HOST']);
  return preg_match('/^\[?(?:[a-z0-9-:\]_]+\.?)+$/', $_SERVER['HTTP_HOST']);
}

A fix is due for subsequent drupal versions, so we won't have to keep patching this.

2)
Many hosts don't allow wget. In this case you may have to use something like:

php /home/[username]/public_html/cron.php

Further advice, I would get it working without any switches, before attempting to add them in.
I found that my host wouldn't allow some of them, which stop cron working at all.

GavinC’s picture

Ok i have changed the bootstrap.inc Line 279 to what you have suggested. I will try and see if this runs.

Thank you for your help :)

-Anti-’s picture

> Ok i have changed the bootstrap.inc Line 279 to what you have suggested. I will try and see if this runs.

Remember that if you are affected by the http_host thing, cron might *still* not run due to 2) or something similar. So I would just keep the edit in no matter what; it won't do any harm, and will take one potential problem out of the equation for further troubleshooting.

Just to show you how finicky it can be, this line doesn't run on my host (cpanel backend):
php /home/[name]/public_html/dev/cron.php > /dev/null
however, this does:
php /home/[name]/public_html/dev/cron.php> /dev/null

But the first one (space before the chevron) is what was in all the tutorials!
It took me two solid days to get cron working due to this little anomaly.

Also, another thing to watch out for: If you get a cron command to run but it silently crashes apache, you'll get a dump placed in your drupal root. these files are large, and can be generated every time a malformed cron command is run. So don't leave your cronjob overnight until you are sure that everything is fine (yes, I did go to bed and woke up to find my webspace full).

GavinC’s picture

ok after the change i have no cron running or an error report.

@Anti:

Where is this line?

php /home/[name]/public_html/dev/cron.php > /dev/null
however, this does:
php /home/[name]/public_html/dev/cron.php> /dev/null
-Anti-’s picture

That is for the 'cpanel-11' backend which many, if not most, webhosts provide for their customers.
There is a 'cron section' and a text field in which to type the command.
The example was just to show you that one wrong character can stop cron from running completely.

GavinC’s picture

ahhhh, got you. ok well after some messing about, i have finally got Cron to run. Thanks for your help.