清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#! /bin/sh # 由于数组在shell函数中传递实在蛋疼,尤其是还包括其他参数时,所以干脆变量全部用全局变量 random_v=$RANDOM trap "rm -f /tmp/$$.$random_v.http_code.out" EXIT function curl_url(){ url_line="http://$url_host/$line" /usr/bin/curl -s -o /dev/null --connect-timeout $time_out -m $time_out -w %{http_code} $url_line > /tmp/$$.$random_v.http_code.out return $? } function deal_url(){ error_status=7 n=0 max_fail=30 ips_length=${#ips[@]} url_host=${ips[$n]} cat $urls_txt | while read line; do curl_url if [ $? -eq $error_status ];then echo "当前IP:${url_host}无法连通,尝试下一个IP连接$line" if [ $n -lt $max_fail ];then n=$(( $n+1 )) visit_ip=$(( $n % $ips_length )) #应该使用哪一个ips数组下标 url_host=${ips[$visit_ip]} curl_url while [ $? -eq $error_status ] do echo "当前IP:${url_host}无法连通,尝试下一个IP连接$line" n=$(( $n+1 )) visit_ip=$(( $n % $ips_length )) url_host=${ips[$visit_ip]} if [ $n -ge $max_fail ];then echo "尝试次数达到最大值,放弃连接" exit fi curl_url done else echo "尝试次数达到最大值,放弃连接" exit fi fi echo "通过IP:${url_host}完成对${line}的访问,返回状态为$(cat /tmp/$$.$random_v.http_code.out)" done } work_dir='' cd $work_dir ips=( '10.12.12.11:8090' '10.12.12.12:8080' '10.12.12.13:8080' '10.12.12.14:8080' '10.12.12.15:8080' ) urls_txt="$work_dir/url.list" time_out=5 deal_url