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 :

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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -