Results 1 to 4 of 4

Thread: Here's A Strange One

  1. #1
    charlesh's Avatar
    charlesh is offline Master Glow Jedi
    Join Date
    Aug 2006
    Location
    Atlanta, GA - better than you imagined it would be.
    Posts
    189

    Default 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

  2. #2
    charlesh's Avatar
    charlesh is offline Master Glow Jedi
    Join Date
    Aug 2006
    Location
    Atlanta, GA - better than you imagined it would be.
    Posts
    189

    Default 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

  3. #3
    sergey is offline Master Glow Jedi
    Join Date
    Aug 2005
    Posts
    472

    Default

    Charles,

    Thanks for the explanation. Glad to hear you figured it out.

  4. #4
    jmarcv's Avatar
    jmarcv is offline Cranky Coder
    Join Date
    Jan 2005
    Posts
    354

    Default

    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

Similar Threads

  1. Strange Email issue
    By charlesh in forum WHM, Resellers, VPS and Dedicated Hosting Topics
    Replies: 2
    Last Post: 08-18-2008, 10:48 AM
  2. Strange security issue
    By ampm designs in forum General Support
    Replies: 4
    Last Post: 03-03-2006, 01:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14