Results 1 to 10 of 10
  1. #1
    Junior Member
    Join Date
    Dec 2006
    Posts
    7

    Default Getting php script to run as cron

    I've tried every possible way that I could think of and I still can't get this cron job to work. I've tried:

    15 12 * * * /usr/local/bin/php /var/www/cgi-bin/getinjuries.php
    15 12 * * * wget http://www.mydomain.com/admin/getinjuries.php
    15 12 * * * lynx http://www.mydomain.com/admin/getinjuries.php

    etc, etc

    The script parses a log and then dumps it into my db.

    File is chmod to 755.

    Preferably I would like to run it outside the www. Any pointers?

  2. #2
    Senior Member rolling's Avatar
    Join Date
    May 2004
    Location
    Different day, different place
    Posts
    486

    Default

    Quote Originally Posted by esiason14
    15 12 * * * /usr/local/bin/php /var/www/cgi-bin/getinjuries.php
    Should work. Try it from the command line. If it works there, try logging the output to a file

    Code:
    15 12 * * * /usr/local/bin/php /var/www/cgi-bin/getinjuries.php >/usr/home/yourlogin/injuries.log
    Richard

    I have jotted down some of my meddlings at http://www.rollingr.net/wordpress
    Click here for a full list of formatting codes for this forum

  3. #3
    Junior Member
    Join Date
    Dec 2006
    Posts
    7

    Default

    Quote Originally Posted by rolling
    Try it from the command line.
    Thanks for the quick response. How would I do that ^^

  4. #4
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,720

    Default

    You log into your account via SSH and the putty program and then run the php script. Have you ever done that? The WH manual has a link to putty and some general guidelines on setting it up and logging in. The actual command in putty you would run is.
    Code:
    php /var/www/cgi-bin/getinjuries.php
    I also do not think that in your corn job you need to supply the path to php but not 100% sure on that.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  5. #5
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,720

    Default

    Here is the link to the WH manual area on SSH
    http://www.helpdocs.westserver.net/s...H_Software.htm
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  6. #6
    Junior Member
    Join Date
    Dec 2006
    Posts
    7

    Default

    Ok, yes...I have done that and it does run. Also if I run it from a browser it runs fine too. So I guess I have to set up a log to find out where the cron is dying. Can you help me out with that as well?

  7. #7
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,720

    Default

    All you need to do is add this to the end of the line as Richard has indicated:
    Code:
    >/usr/home/yourlogin/injuries.log
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  8. #8
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,720

    Default

    I was going back looking at some of the old post on this subject to refresh my memory and one thing I found is that a user was having problems because the php script they where running had relative paths in it. So that is something you might want to check in your php script.
    Reference: http://forums.westhost.com/showthread.php?t=9178
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  9. #9
    Junior Member
    Join Date
    Dec 2006
    Posts
    7

    Default

    wildjokerdesign, thanks for taking the time to check into this. That did it. I tested it out and it's finally working!! Thanks again!

  10. #10
    Senior Member rolling's Avatar
    Join Date
    May 2004
    Location
    Different day, different place
    Posts
    486

    Default

    Quote Originally Posted by wildjokerdesign
    The actual command in putty you would run is.
    Code:
    php /var/www/cgi-bin/getinjuries.php
    I also do not think that in your corn job you need to supply the path to php but not 100% sure on that.
    It is vital that you use the same path in your test and the Cron job.

    Jobs which are run by cron do not run in the same environment as us mere mortals, since it does not log in. It is therefore quite possible that environment variables (such as path) are different. For this reason, you should always use absolute paths (/usr/local/bin/php and not just php) in the specification of of your job and in your scripts.
    Richard

    I have jotted down some of my meddlings at http://www.rollingr.net/wordpress
    Click here for a full list of formatting codes for this forum

Similar Threads

  1. Need Cron Job Primer (I think!)
    By ccwebb in forum PHP / MySQL
    Replies: 3
    Last Post: 10-02-2005, 01:48 PM
  2. Getting Cron to run a PHP file
    By kc0eks in forum General Discussion
    Replies: 3
    Last Post: 01-22-2005, 01:05 PM
  3. Cron PHP Script - Read file problems
    By grim in forum PHP / MySQL
    Replies: 2
    Last Post: 07-12-2004, 11:45 AM
  4. PHP script to run a club.
    By Armadillo in forum PHP / MySQL
    Replies: 5
    Last Post: 05-19-2004, 10:17 PM
  5. Setting up a cron for a PHP script
    By rl in forum PHP / MySQL
    Replies: 2
    Last Post: 01-20-2004, 04:28 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
  •