Need help with cron job!

zachjallen39

New Member
Messages
6
Reaction score
0
Points
1
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
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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:
Top