How to run cron on Drupal 6 from shell script with correct paths

This is how you can run cron on Drupal 6 from a shell script and get out more of the cron run than via HTTP.

First make sure what you can run PHP via console by testing a simple PHP script.

You might not use the same php.ini as the webserver, create a echo phpinfo(); file and find out

Increase values:

max_execution_time = 5000

max_input_time = 5000

memory_limit = 1000M

post_max_size = 750M

upload_max_filesize = 750M

implicit_flush = On

display_errors = Off

html_errors = Off

register_argc_argv = On

Create a php file, basically a copy of cron.php and call it fullpathcron.php and place it in the drupal installation folder

Change permission by chmod 755 /var/www/mysite/fullpathcron.php

<?php
  $_SERVER
['HTTP_HOST'] = '<a href="http://www.mysite.com';
">www.mysite.com';
</a> 
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
 
$_SERVER['SERVER_SOFTWARE'] = NULL;
 
$_SERVER['REQUEST_METHOD'] = 'GET';
 
$_SERVER['QUERY_STRING'] = '';
 
$_SERVER['HTTP_USER_AGENT'] = 'console';
 
  include_once './includes/bootstrap.inc';
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  drupal_cron_run();
?>

Create a shell script file in the drupal installation folder or somewhere else called cronRun.sh and add your call to the new fullpathcron.php file.

cd /var/www/mysite/
php fullpathcron.php

Set cron by crontab -e

*/5 * * * * /var/www/mysite/cronRun.sh

for cron every 5 minutes, Ctrl+O, Ctrl+X to save

Wait and check the db log

Tips and Tricks: PHP Shell Scripts: http://blog.digitalstruct.com/2007/04/24/tips-and-tricks-php-shell-scripts/

Knowledge keywords: