bash - ip proxy testing using wget not working -
i testing ip:port proxy downloading see if of these proxy valid or not. working script
#!/bin/bash pro in $(cat testing.txt);do wget -e use_proxy=yes -e http_proxy=$pro --tries=1 --timeout=15 http://something.com/download.zip if grep --quiet "200 ok"; echo $pro >> ok.txt else echo $pro >>notok.txt fi done
typical output on success wget
--2014-06-08 10:45:31-- http://something.com/download.zip connecting 186.215.168.66:3128... connected. proxy request sent, awaiting response... 200 ok length: 30688 (30k) [application/zip] saving to: `download.zip' 100%[======================================>] 30,688 7.13k/s in 4.2s
and output on failure
--2014-06-08 10:45:44-- http://something.com/download.zip connecting 200.68.9.92:8080... connected. proxy request sent, awaiting response... read error (connection timed out) in headers. giving up.
now problem , grep seems not working! output ip address in notok.txt file. weather wget success or not output address in notok.txt . how can solve this?
here corrections :
1) should avoid use for in $(cmd)
. should read :
- this reminder on how read command output or file content loop in bash ;
- this reminder the necessity (or not) protect variables double quotes.
2) grep
must read stream :
grep [options...] [pattern] file command|grep [options...] [pattern] grep [options...] [pattern] < <(command) grep [options...] [pattern] <<< "some text"
3) no need use grep
in case :
#!/bin/bash while read -r pro; out="$(wget -e use_proxy=yes -e http_proxy=$pro --tries=1 --timeout=15 http://something.com/download.zip)" if [[ $out =~ "200 ok" ]]; echo "$pro" >> ok.txt else echo "$pro" >> notok.txt fi done < testing.txt
Comments
Post a Comment