-
Here's A Strange One
I have a php script that I have (trying) to run on a cron job. Basically, this script will output a log file to the same directory in which it lives. When I
execute the script from within the directory, it executes fine and updates the log file. that is using the command from the shell:
Code:
php -f expiration_check.php
But, when I execute that from a cron job, It seemingly does its job, but doesn't update the log file as when I execute from the directory it is in. Here is the cron command:
Code:
/usr/local/bin/php /home/my_web_user/non_public/expiration_check.php
I have the non_public directory in the user's root directory, not the server root. So, why does it not update the log file with that cron command? Any ideas? The times on the files seem to change, however, with the cron run, just not the text inside. But I know it is working in the script, because I get a sucessful execute from the shell, in that directory?
Do I have to specify the full path in the script for the log file as well? That is one thought. Any ideas?
Thanks,
CharlesH
-
Strange answer
You know, if my relatives call me with computer questions, I usually let it go to voice mail and call them an hour later. The answer is usually, "Oh, nevermind, I figured it out." That small bit of time usually saves me some time providing family "customer support".
So, with a little time and determination, most problems are solved. Having said that, I figured out the above problem(s) with the cron.
First of all, most of the problems were in the script itself. The first one was that when I was executing the script and it was working, I was logged in as root, not the user. This automatically gave the log file I was creating permissions as the root as the owner, not my user. So, I erased the file and let the cron script create it and this solved the owner permissions problem.
The second problem was that if you are using the php command line interface, all of your include files and references to files must have the full path spelled out - /home/my_user/blah/include.php This also was required for the script to write out the log file: /home/my_user/blah/logfile.txt
So, with that it worked. I also set the cron to run every couple of minutes while I was making / testing changes. That seemed to help in the debug process.
Hope this helps somebody.
Charlesh
-
Charles,
Thanks for the explanation. Glad to hear you figured it out.
-
Ah, the old 'let it sit and ferment' syndrome.
To keep script paths as is without having to mod to full paths, you can always 'stack' commands like this:
cd /home/my_web_user/non_public/; /usr/local/bin/php expiration_check.php