Forum Moderators: coopster
see php.net commandline features [es2.php.net]
my crontab looks like:
/opt/bin/php -q /var/www/htdocs/scripts/test.php
when i run the script from the /var/www/htdocs/scripts directory it runs fine:
% /opt/bin/php -q test.php
but when i use the full path to the script in the cron job, it exits with the error message "no input file specified".
apparently i need to add the SCRIPT_FILENAME var to the env variables - does anyone know how to do this? or should i simply install an older version of php as cgi?
many thanks
#!/opt/bin/php so that the file looks like
#!/opt/bin/php
<?php
..blah
and set execute permissions on that file for the relevant user (i.e. whichever user owns the crontab).
thanks for input, but that idea desn't work either. this is getting weirder and weirder.
sometimes using the full path works and then 1 minute later for no apparent reason it does not work. i am not changing anything between tries.
it still will not work consistently when i use the full path.
hmmmm
If you make the php script executable, then you don't need to invoke the php parser directly.
In other words, your line in the crontab can just read:
/var/www/htdocs/scripts/test.php If the script has execute permissions set, then the server will see the first line (#!/opt/bin/php) and use this program to execute the remainder of the script.
You should test that the test.php script is executable by just running it from the command line:
% /var/www/htdocs/scripts/test.php Apologies if you already know this!
thanks for your step by step guide.
i have done as you say and when i run ./test.php it returns "bad interpreter: no such file or directory"
the shebang line is identical to another php script (with a simple mail() function) which works fine ./testmail.php
the script works perfectly if called in the browser.
i think we are getting somewhere ;)
Off the top of my head there are a couple of reasons why the test.php script isn't working.
1 - The shebang line should have *no spaces* in it, and should point to the php interpreter
2 - You may have created the script on a Windows machine, and the text file has Windows line breaks ("\r\n"). Unix line breaks have a different format ("\n").
Open the the test.php file in a unix text editor, and replace those linebreaks. Alternatively, use a Windows text editor like Textpad and save test.php as Unix format.