|
|
Question : How to get wget command output to a variable
|
|
I use the wget command to another server that processes the url via a php script into a mysql database. The command I use for wget is:
wget -q -o /dev/null -O temp.log "http://address/raw_log_data.php?pross_type=1&filename=$filename&user_id=$user"
What I want to be able to do is instead of logging the output of my php script into temp.log I would like to put it into a variable. The php script will output a 1 if successful and a 0 if an error occured. Then I would use that variable to determine if I would continue to process that log file.
|
Answer : How to get wget command output to a variable
|
|
Maybe I'm missing something, but this sounds too easy. I assume you're doing the wget in a shell script (you didn't specify). You'd just do:
RESULT=`wget -q -O - "http://address/raw_log_data.php?pross_type=1&filename=$filename&user_id=$user"`
I don't really think you need the "-o /dev/null"--that's what -q does. Then you can test $RESULT, but you should first test $? to see if wget encountered any errors. I would suggest testing "$RESULT" (with the quotes) just in case it's not a 0 or 1.
This is basic shell scripting. Do you know how to write the rest of the script?
If you can modify the PHP code I might suggest it would be far more efficient to add a method to iterate until failure in one run rather than have the wrapper script that calls the php multiple times.
Hope this helps, Tim
|
|
|
|