Cron reports "Could not open input file"

I have a php script that I am trying to set up as a cron…

I am having a funny problem. I can run my command through the shell without problems, but when I put it in a cron, it does not work.

To troubleshoot, I asked it to email me and it sends an email with the following in the body:

Could not open input file: /home/USERNAME/script.php

(USERNAME is my user name)

At the command line, I have typed:
/usr/local/php5/bin/php /home/USERNAME/script.php
And it runs the script with the expected output.

My crontab is as follows:
*/3 * * * * /usr/local/php5/bin/php /home/USERNAME/script.php

It does run every 3 minutes as expected, but generates the email error every time. I have copied and pasted the command from my crontab to the commandline, and it runs without problems. I have copied and pasted my functioning command from the commandline to the crontab and that doesn’t work. Therefore I know there are no typos in the command in my crontab!

I tried adding a line to the top of my PHP file:
#!/usr/local/php5/bin/php -q
And it did not help.

I tried using $HOME/script.php instead of /home/USERNAME/script.php and that gave the same results - works on the command line, does not work in cron job.

I tried changing the permissions of the php file to 744 and to 755, neither worked.

I would prefer not to have the script in a web accessible folder, simply because it does not need to be accessed by anyone except me, so why would I introduce any security risks? So I suppose I could put it in a public folder and just do an html fetch in cron, but that seems like the wrong solution.

Any advice is appreciated!



This is getting worse. Am I being sabotaged?

I moved my php file to a web-accessible directory, use wget to access it, and I get the following error:

HTTP request sent, awaiting response… 404 Not Found
10:15:01 ERROR 404: Not Found.

but I noticed that wget appears to be appending “” to the end of my URL


the file that I was feeding to crontab had windows CR LF line endings. Changed it to UNIX line endings and it’s working.

Never would have figured it out without that wget error…