Posted by gallamine on July 17, 2009 at 2:07pm
Howdy,
I'm trying to set up a cron job to run my cron.php file every hour. I've read through the docs on cron on Drupal.org (http://drupal.org/cron), and I tried executing the following commands, just to test:
wget -O - -q -t 1 http://www.example.com/cron.php
OR
curl --compressed http://example.com/cron.php
The problem is is that I have a .htpasswd file on my site that restricts access, and curl and wget can't get to the page.
So, is there an easy way of allowing them to access the cron.php files?
I've considered just using Drupal itself to restrict access to unregistered users, but I'd rather not have to modify my site's look/feel while I'm development, and the "unregistered" view is a big component. Also, I don't want Google snooping around.
Comments
How about calling it
How about calling it directly from cron, via something like "5 * * * * /usr/bin/php -f .../cron.php"
__
Ray Downes, rkdownes@waketech.edu
919-866-5563
Cron Job
I know of three methods
45 * * * * /usr/bin/lynx -source http://example.com/cron.php
45 * * * * /usr/bin/wget -O - -q -t 1 http://www.example.com/cron.php
45 * * * * curl --silent --compressed http://example.com/cron.php
However, I was unable to use any of them as none of those commands was available to me. So I downloaded a module to do this.
PoorMansCron
http://groups.drupal.org/node/24357#node_links_group
What this does is when someone accesses the page, it checks to see how long ago the last access was and if it is longer then the timeout, 1 hour in your case, it runs the cron job for you, then loads the page. This shouldn't take enough time for the user to notice but then, that depends on what your cron job is actually doing.
curl command line options for cron job
You need to either put the username/password for your .htpasswd on the command line or add it to a .netrc file if you can use that. For curl:
curl -u username:password --silent --compressed http://example.com/cron.php
curl can also read from a .netrc file in your account's home directory using this syntax:
curl -n --silent --compressed http://example.com/cron.php
The format of the file is:
machine example.com login username password yoursecret
--[Lance]
Drush can help
If you're not already in love with drush, this might do it for you. We lock down our test and stage sites with htpasswd, and use drush to run their crons:
*/5 * * * * /usr/bin/drush -r /vol/www/staging cron > /var/log/staging-cron.out 2&>1
Check out my meetup organizing tool and my conference CFP tool.
Other options
IP restrictions, using HTTP auth user and password in the request url (low security isn't really an issue here).
Ken Winters