+ Reply to Thread
Results 1 to 2 of 2

Thread: Need help with cron job!

  1. #1
    zachjallen39 is offline x10Hosting Member zachjallen39 is an unknown quantity at this point
    Join Date
    Aug 2011
    Posts
    1

    Question Need help with cron job!

    Hi all,
    I'm trying to set up cron jobs to first download a remote file, second to update a db, and third to perform some final calculations.

    Here is my cron job to download a remote file:
    wget -O - /home/csk/ultrastats/src/admin/parser.php?op=getnewlogfile&id=1

    job to update db:
    php -cron -q /home/csk/ultrastats/src/admin/parser.php?op=updatestats&id=1

    job to perform final calcuations:
    /usr/bin/php /home/csk/ultrastats/src/admin/parser.php?op=runtotals

    As you have noticed I used a different method per job, the only reason for this was error testing to see which would work. None have worked, my page does not say the database was updated and i do not receive an email at all.

    Thank you,
    zach

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Need help with cron job!

    wget takes a URL as an argument, not a pathname. Moreover, pathnames don't support query strings. Third, the ampersand is a special character in most shells, marking the end of a command and causing it to be run in the background; to prevent this, you'd need to quote the URL.

    Is the script supposed to send an e-mail? Last I heard, e-mailing the output was disabled. If you want the script output, you'll need to capture it. For example:

    Code:
    /usr/local/bin/php -q $HOME/ultrastats/src/admin/parser.php updatestats -i 1 > $HOME/log/ultrastats.update.$(date '+%Y-%m-%d-%H:%M').log 2>&1
    /usr/local/bin/php -q $HOME/ultrastats/src/admin/parser.php runtotals > $HOME/log/ultrastats.totals.$(date '+%Y-%m-%d-%H:%M').log 2>&1
    Unless the same page is supposed to be accessed from the web, use the command line PHP binary to run the script and pass the arguments as typical command line arguments (accessible via $argv; you'll need to adapt your script using e.g. getopt). Alternatively, you could set the query string environment variable on the command line, then parse it into an array in the script using parse_str:

    Code:
    QUERY_STRING='op=getnewlogfile&id=1' /usr/local/bin/php -q /home/csk/ultrastats/src/admin/parser.php > $HOME/logs/ultrastats.$(date '+%Y-%m-%d-%H:%M').log
    The first two commands will fail if the path variable doesn't include the directory that the binary is in. Try using the full path for the commands, and if wget won't work, use curl.
    Last edited by misson; 01-11-2012 at 02:15 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Cron job
    By rickje in forum Free Hosting
    Replies: 2
    Last Post: 05-09-2010, 05:06 PM
  2. Replies: 6
    Last Post: 11-14-2009, 06:38 PM
  3. Can a cron job kick off another cron job?
    By dmoneyman in forum Programming Help
    Replies: 8
    Last Post: 04-03-2009, 08:04 PM
  4. [cron problem]php-cron command not found
    By N4rk0 in forum Free Hosting
    Replies: 1
    Last Post: 01-31-2008, 11:51 AM
  5. Cron
    By KingOfTheEmblem in forum Free Hosting
    Replies: 6
    Last Post: 12-09-2007, 07:06 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers