0

I am getting a slew of errors when I attempt to run a cron job following my hosting company's instructions. From researching the errors, I suspect the instructions are wrong. But their support is telling me this is a development issue and they can't help me. So I hope someone here can tell me the correct way to run cron in this environment.

The site is running without error. Cron runs successfully by using "admin/reports/status/run-cron" or by using the URL provided for running cron from outside the site.

The instructions say to use the following command: cd /home/username/public_html && php /home/username/public_html/cron.php >/dev/null 2>&1

This fails silently, meaning that nothing happens that I can see, but the status report does not indicate that cron has run. So I removed the ">/dev/null ..." part in order to allow the system to send me a result e-mail. Thus the command I'm using now is: cd /home/username/public_html && php /home/username/public_html/cron.php

When this command executes, I get an e-mail with hundreds of errors, mostly like: Notice: Undefined index: argc in /home/username/public_html/includes/bootstrap.inc on line 3407 Notice: Undefined index: SCRIPT_NAME in /home/username/public_html/includes/bootstrap.inc on line 1622

I found a forum post about the same kind of problem, and the offered solution was to "Use a URL to cron.php with wget or curl." Unfortunately, my Unix is rusty and I don't know how to do that.

Can someone suggest how to modify the command in the host instructions so that cron will run correctly?

Thanks for your help.

1

You shouldn't run cron.php throught php cli. basically you should have a line like this in your crontab file:

0 * * * * wget -O - -q -t 1 http://www.example.com/cron.php

but you also need to append security token to the url.

by reading Configuring cron jobs using the cron command page you will get a better idea of how it works.

  • Looks like OP is using bargain bin shared hosting. How do you know he has (access to) a crontab? – Free Radical Jun 27 '15 at 12:38
  • It took some work to figure out how to implement your answer, but working with host support on the phone, we finally figured out that the command in the instructions had to be replaced with the part of your answer starting with "wget" and followed by "?cron_key=<key>", where the key is given at "/admin/config/system/cron". I presume this key is what you meant by the security token. The support person has promised to notify the person responsible for the knowledgebase to update the instructions for Drupal 7. – NewSites Jun 27 '15 at 14:37
  • @FreeRadical the instructions link on his answer is talking about cpanel so I guessed he's using the cpanel hosting and through cpanel interface you can manage cron jobs. – sepehr Jun 27 '15 at 14:53
  • @NewSites sorry my answer wasn't too precise cause I was busy. yes what I meant was cron_key query parameter which acts as a security token to prevent cron invokation by some stranger. glad you manged to figure it out. – sepehr Jun 27 '15 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.