Hello. Sorry for my bad english.

I'm trying to set cron.php calls from crontab.
When i run cron.php from browser (chmod 755) - it works, when its calling by crontab - errors happen.

Here is these errors:

PHP Warning:  main(sites/default/settings.php): failed to open stream: No such file or directory in /home/_myaccount_/www/includes/bootstrap.inc on line 642
PHP Warning:  main(): Failed opening 'sites/default/settings.php' for inclusion (include_path='.:') in /home/_myaccount_/www/includes/bootstrap.inc on line 642
PHP Warning:  main(includes/database.inc): failed to open stream: No such file or directory in /home/_myaccount_/www/includes/bootstrap.inc on line 643
PHP Warning:  main(): Failed opening 'includes/database.inc' for inclusion (include_path='.:') in /home/_myaccount_/www/includes/bootstrap.inc on line 643
PHP Warning:  main(includes/session.inc): failed to open stream: No such file or directory in /home/_myaccount_/www/includes/bootstrap.inc on line 644
PHP Warning:  main(): Failed opening 'includes/session.inc' for inclusion (include_path='.:') in /home/_myaccount_/www/includes/bootstrap.inc on line 644
PHP Warning:  main(includes/module.inc): failed to open stream: No such file or directory in /home/_myaccount_/www/includes/bootstrap.inc on line 645
PHP Warning:  main(): Failed opening 'includes/module.inc' for inclusion (include_path='.:') in /home/_myaccount_/www/includes/bootstrap.inc on line 645
PHP Fatal error:  Call to undefined function:  db_fetch_object() in /home/_myaccount_/www/includes/bootstrap.inc on line 199

Note: this errors have appears only when calling cron.php from crontab (in other scripts bootstrap.inc works fine).

In bootstrap.inc (642-645):

        include_once "$config/settings.php";
        include_once 'includes/database.inc';
        include_once 'includes/session.inc';
        include_once 'includes/module.inc';

All inc-files are found where it is necessary (in includes/).

Can you help me?

Comments

OZ’s picture

I'm hope, that my posts will be useful for somebody.

I've just add in bootstrap.php
if (getcwd()=='/home/my_account') chdir('my_syte/www/');

For example, it's can to look as:
if (getcwd()=='/home/host12345') chdir('example.com/www/');

With best regards, OZ. Drupal is genius system! :)

jj’s picture

Hello,
I am getting the same errors. While your solution seems to be on the right track, the explanation is too arcane for me. Are you referring to the bootstrap.inc file? And, where in the file do I put the chdir command?

OZ’s picture

I've put chdir at line 641 in bootstrap.php (before include_once "$config/settings.php";).

My crontab works orderly, but when script script is caused from it, the current dir becomes the directory of crontab, but not of script directory.
I simply check this (getcwd) and correct (chdir).

sorry for my english.

jj’s picture

I have spent days of frustration trying to work this out. Your solution is simple and elegant. I think this is a bug in the programming that should be addressed.
My cron jobs are now running smoothly.

alexmc’s picture

Can you tell us what your crontab line is? - I think that must be wrong.

andre75’s picture

While you are helping people with the crontab:

50 10 * * * /usr/local/bin/php $HOME/htdocs/site1/cron.php >>$HOME/htdocs/savelogs/cron_oti.log 2>>$HOME/htdocs/savelogs/cron_oti.err

(It's all one line). It does not get executed and I see no log files either. /usr/local/bin/php is the correct path for my hosting provider.

Andre

-------------------------------------------------
http://www.opentravelinfo.com
http://www.aguntherphotography.com

jj’s picture

Hello and thanks for responding. My crontab line is:

/usr/local/bin/php /hsphere/local/home/concresc/drumcirclereview.com/cron.php

Here is the email I am getting from the cron job:

Warning: main(sites/default/settings.php): failed to open stream: No such file or directory in /hsphere/local/home/concresc/drumcirclereview.com/includes/bootstrap.inc on line 642

Warning: main(): Failed opening 'sites/default/settings.php' for inclusion (include_path='.:/usr/local/lib/php') in /hsphere/local/home/concresc/drumcirclereview.com/includes/bootstrap.inc on line 642

Warning: main(includes/database.inc): failed to open stream: No such file or directory in /hsphere/local/home/concresc/drumcirclereview.com/includes/bootstrap.inc on line 643

Warning: main(): Failed opening 'includes/database.inc' for inclusion (include_path='.:/usr/local/lib/php') in /hsphere/local/home/concresc/drumcirclereview.com/includes/bootstrap.inc on line 643

Warning: main(includes/session.inc): failed to open stream: No such file or directory in /hsphere/local/home/concresc/drumcirclereview.com/includes/bootstrap.inc on line 644

Warning: main(): Failed opening 'includes/session.inc' for inclusion (include_path='.:/usr/local/lib/php') in /hsphere/local/home/concresc/drumcirclereview.com/includes/bootstrap.inc on line 644

Warning: main(includes/module.inc): failed to open stream: No such file or directory in /hsphere/local/home/concresc/drumcirclereview.com/includes/bootstrap.inc on line 645

Warning: main(): Failed opening 'includes/module.inc' for inclusion (include_path='.:/usr/local/lib/php') in /hsphere/local/home/concresc/drumcirclereview.com/includes/bootstrap.inc on line 645

Fatal error: Call to undefined function: db_fetch_object() in /hsphere/local/home/concresc/drumcirclereview.com/includes/bootstrap.inc on line 199

Tell me if I am wrong but it appears that crontab is finding the cron.php since it is making its way to the bootstrap.inc file. From there, however, it seems to not be able to find the other include files. I am assuming that it is a path problem.

What do you think?

Thanks for the help.
JJ

jj’s picture

I thought this could be solved by using one of the .sh scripts provided but my provider does not seem to have a lynx editor. I have tried both the cron-lynx.sh and the cron-curl.sh scripts and numerous combinations of path statements to no avail. The above crontab line is what was recommended by my ISP.
Thanks again,
JJ

OZ’s picture

Yes, you are absolutely right. I have answered above.

OZ’s picture

alexmc - November 10, 2005 - 00:39

Can you tell us what your crontab line is? - I think that must be wrong.

All cron-tasks executes orderly.
And in Drupal-modules too (after correcting).

Ainur’s picture

I have the same error messages, my command is:

00 17 * * * php /home/httpd/vhosts/mysite.com/httpdocs/cron.php
Ainur’s picture

OZ, привет! ;)
There is more elegant way to do that, without changing Drupal’s code.

Use this command line:

cd /home/httpd/vhosts/yoursite.com/httpdocs/; php cron.php

explanation: first set up current directory, then run the script.

eelkeboezeman’s picture

Nice one, that really did the trick. For me I had to execute (second part of the command, after the ; ) the php-parser like this:

/usr/local/bin/php -q -f cron.php

this is in DirectAdmin, but it wil probably work on other systems as well

idflorin’s picture

didn't work for me :(

sunward’s picture

this is simple and worked nicely.

yelbetan’s picture

Why don't you try curl?

It worked for my drupal set up.

Here's the link to the topic "Multisite with cron-curl.sh"

http://drupal.org/node/237506

It works for both single and multi-site.

ralgh’s picture

I found this to work well on a Rackspace Cloud Site environment.

The problem I ran into was that the current working directory cron was running "cron.php" in was not the Drupal doc root. It was something like "mnt/stor2-xyz1/1234455". Because of this php was looking for "includes/bootstrap.inc" in this directory.

I created a new file named "cron-cron.php" with the following code:

<?PHP

$doc_root = dirname($_SERVER["SCRIPT_FILENAME"]);
chdir($doc_root);

include_once './cron.php';

?>

$_SERVER["SCRIPT_FILENAME"] equals something like "/mnt/stor2-ab1-xyz1/1234455/www.mysite.com/web/content/cron-cron.php"

The php function "dirname()" chops off the "cron-cron.php" from "$_SERVER["SCRIPT_FILENAME"]" resulting in the correct document root. ($_SERVER["DOCUMENT_ROOT"] was returning the wrong path too: "mnt/stor2-xyz1/1234455")

Then chdir() sets the current working directory to the correct Drupal document root path. Now all subsequent includes in the script will look in the correct directory.

By naming the file to something other than "cron.php" and including the original we will not need to worry about overwriting our changes on the next Drupal upgrade.

This solution should work (but not tested) with most other environments as well.

Hope this helps someone and please let me know if it does not.

The cron command I am running through the cron control panel is similar to "php /mnt/stor2-ab1-xyz1/1234455/www.mysite.com/web/content/cron-cron.php"

My current Drupal version used is: 6.16

iaugur’s picture

Thanks Ralph - good solution!

George Boobyer
www.blue-bag.com

ludo.r’s picture

Works great, thank you!