Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a php file under php called test.php set to run every 5th minute of the hour. When ever I run the file manually (by going to the web browser and runnint the path) it works fine. But when the cron job tries to run it I get the error message

my cron job is

#### Delete Records
5 * * * * /var/www/html/phpsysinfo/cronUpdateLeadBucketOnEnergycAlliance.php

my phpfile is (path : /var/www/html/phpsysinfo/phpfile)

<?php 
require("dbconnect.php");
 $sql = mysql_query("DELETE FROM list where status <> 'LEAD'") or die(mysql_error());
?>

and the error that I get is:

/var/www/html/phpsysinfo/phpFile.php: line 1: ?php: No such file or directory
/var/www/html/phpsysinfo/phpFile.php: line 2: syntax error near unexpected token `"dbconnect.php"'
/var/www/html/phpsysinfo/phpFile.php: line 2: `require("dbconnect.php");

thanks

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

You're missing the call to the php binary in your cron, it should look like this

### Delete Records
5 * * * * php -q /var/www/html/phpsysinfo/cronUpdateLeadBucketOnEnergycAlliance.php

Please substitute php with php-cli depending on how the php command line binary is named on your distribution :)

share|improve this answer
2  
...you will probably have to specify the path to the php binary too. –  David Mackintosh Feb 1 '11 at 15:12
    
only if php is in a location not available in the PATH but yeah, good point :) +1 –  lynxman Feb 1 '11 at 15:20
    
ok, strictly speaking you "should" include the path to the php binary so that you are explicit about what you are running and not getting hijacked by something unexpected in the path. –  David Mackintosh Feb 1 '11 at 16:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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