Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wget screen output can't be redirected to a log file using shell script

Tags:

shell

I have s shell script, the content is as below I hope the screen output could be redirected to templog, the screen output not the html content but is like

--2012-10-30 15:53:14--  http://www.youtube.com/results?search_query=pig
Resolving www.youtube.com... 173.194.34.5, 173.194.34.6, 173.194.34.7, ...
Connecting to www.youtube.com|173.194.34.5|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “search_result”

    [ <=>                                   ] 108,503     --.-K/s   in 0.07s   

2012-10-30 15:53:15 (1.40 MB/s) - “search_result” saved [108503]

but it can't I tried 2>&1|cat > templog still not OK

you can copy the content and make a wget.sh file and then run it you will notice that the content can not be redirected to templog,

how to deal with this to achieve my target? thanks

keyword=pig
page_nr=3
wget -O search_result http://www.youtube.com/results?search_query=${keyword}&page=${page_nr} > templog
like image 793
user1769686 Avatar asked Oct 15 '25 20:10

user1769686


1 Answers

You just need to put quotes around your url. wget then is using the stderr to print on screen, so you also have to the stderr instead of the stdout (using 2> instead of >):

keyword=pig
page_nr=3
wget -O search_result "http://www.youtube.com/results?search_query=${keyword}&page=${page_nr}" 2> templog
like image 143
enrico.bacis Avatar answered Oct 18 '25 15:10

enrico.bacis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!