sshcroncgi-bin

Cron Job - Could not open input file:


I have set up a php file to run that just echos hello.

<?php
echo hello;
?>

My cron job looks like this:

/usr/local/bin/php -f “/home/username/public_html/mls/test.php”

when my script runs i get a confirmation email that says:

Could not open input file: /home/username/public_html/mls/test.php 

I don't know what is causing this. I am using godaddy's virtual private server with cpanel x installed. I have used the ssh to set permissions 777 on folder and file and still can not get it to run.

Any advice would be helpful. Thanks.


Solution

  • For some reason PHP cannot open the file. Try replacing /usr/local/bin/php -f with "ls -la" to try to crib some more information. Remember to NOT quote the file name in the crontab: php -f filename.php, not php -f "filename.php", unless it contains spaces -- and then it's better to use single quotes.

    Possibly, try "ls -la /home", "ls -la /home/username", "ls -la ~/public_html" and so on.

    Also try appending

    2>&1
    

    to the command line, in case only stdout is mailed to you (I don't really think so, but being sure costs little).

    One other possibility

    The crontab as it is refers /home/username/public_html/mls/test.php - that is, a public HTML directory inside username's commonest value for a home directory.

    It is possible that the cron job is either not running with the appropriate user and privileges, or that the user it "sees" is actually a virtual user - there is no "/home/username" at all - and the "home directory" is elsewhere, possibly even existing just as long as the cron job runs. In this case the solution might be to refer to

    ~/public_html/mls/test.php
    

    or, as described above, to first run a command such as pwd or ls -la to determine exactly where the cron job's current working directory is.

    If this, too, fails, then another workaround could be to invoke the PHP HTTP handler via curl or lynx:

    /usr/bin/curl http://www.thishostname.com/mls/test.php
    

    Possibly using either some environment variable or curl header or _GET option to authenticate to the script as the cron job, and avoid it being accessible from the outside.