在一台linux机器上,需要遍历请求不同的url,需要设备请求的带宽或者请求链接数,书写shell脚本。
#!/usr/bin/bash
#-*- coding:utf-8 -*-
function proload(){
wget -qO /tmp/url.list http://ip/ccdn_analy/url.list
speed_per_sec=5000 #单位是KB/S
url_list="/tmp/url.list"
ip_list=$1
conn_num=$((${bandlimit}*125/5))
date_t=$(date +%Y%m%d%H%M%S)
cd ${dir}
logfile="/tmp/http_url.log"
>$logfile
float_ip=$(ip a show lo | egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}" | egrep -v "^10|^127|^192" | awk 'NR==2')
if [ "$X{yewu_ip}" != "X" ];then
cat ${url_list} | while read line
do
domain=$(echo ${line} | awk 'BEGIN{FS="/"}{print $1}')
http_line=$(echo ${line} | cut -d "/" -f 2-)
http_url="http://"${float_ip}"/"${http_line}
process_num=$(ps aux | grep ${domain} | grep ${float_ip} | grep -v grep | wc -l)
if (( ${process_num} <= ${conn_num} ));then
http_code=$(curl -I -so /dev/null -w %{http_code} ${http_url} -H "host:${domain}")
DATE=$(date +%F-%T)
echo "${DATE} ${http_code} ${line}" >> ${logfile}
if [[ ${http_code} =~ 2[0-9]{2} ]];then
echo curl --limit-rate ${speed_per_sec}K -o /dev/null ${http_url} -H "host:${domain}"
nohup curl --limit-rate ${speed_per_sec}K -o /dev/null ${http_url} -H "host:${domain}" &
fi
fi
sed -i "/${line}/d" ${url_list} 1>/dev/null 2>&1
sleep 2
done
else
echo -e "未获取到该主机的浮动ip"
fi
}
if [ $# == 0 ];then
echo -e "\033[32m 脚本运行形势sh preload.sh 带宽值,单位是Gbps(example:sh test.sh 1)\033[0m"
else
bandlimit=$1 #单位是Gbps
proload bandlimit
fi
网友评论