Link to home
Start Free TrialLog in
Avatar of AdrianSmithUK
AdrianSmithUK

asked on

Cron: Not working

OS: Centos 5.4/Plesk

When I run:

#php -q /var/www/vhosts/website.com/httpdocs/cron.php

cron.php sends me an email.

When I add the following to /etc/crontab - nothing happens.

0-59/1 * * * * php -q /var/www/vhosts/website.com/httpdocs/cron.php

or

*/1 * * * * php -q /var/www/vhosts/website.com/httpdocs/cron.php

I tried restarting the cron daemon but still nothing.

What am I doing wrong?


Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Use the full path to php, e.g. /usr/local/bin/php

Use full paths inside the php script as well, because cron does not run the user's initialization profile, so there will not be the usual environment.

wmp
SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AdrianSmithUK
AdrianSmithUK

ASKER

Dear WoolMilkPork

I tried

*/1 * * * * /usr/bin/php -q /var/www/vhosts/website.com/httpdocs/cron.php

But still nothing. The PHP file just has:

<?php

mail('test@email.com', 'myTest1', 'myTest1');

?>

Any other ideas?
Dear farzanj

The crond service is running.

I tried

* * * * * /usr/bin/php -q /var/www/vhosts/website.com/httpdocs/cron.php

But still no joy.
Dear Kalmax

I tried

* * * * * wget -qb http://www.website.com/cron.php > /dev/null

But no joy I'm afraid.
Next check if it is just this script or it would not schedule anything at all?  Try a simple command running every minute.

I have seen this kind of problem with sometimes invisible characters in the cron file.  So sometimes location of your line is also important.  Put it in the first line.  Just another check for weird problems.

Check the user cron file was created

cat /var/spool/cron*/<userID>

Do you see your file?

I would also check if the user has permission over this script to run it.
Could it be that your php.ini is in a non standard location (such as /usr/local/etc), and that you point to this location by means of the PHPRC variable?

If so, please note that this variable is not available under cron and you should either use

* * * * * PHPRC=/usr/local/etc /usr/bin/php -q /var/www/vhosts/website.com/httpdocs/cron.php

OR

* * * * * /usr/bin/php -c /usr/local/etc -q /var/www/vhosts/website.com/httpdocs/cron.php

Please note that "/usr/local/etc" is just an example for a possible location of php.ini.

wmp

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many thanks chaps.

WMP was correct - It was the 6th field.

Kind Regards,

Adrian