最近需要业务需要上线,上线前,需要测试post接口数据:为了测试的效果选择了不同区域的四个IDC机房做压测,根据测试结果文件,分析测试结果。

    

#!/bin/bash
################################################################
# description: user please is a  ab test  web server
# name: web-server 
# test web:   test ab 
#web test1 result  /home/www/post.josn
# USER        YYYY-MM-DD - ACTION
# bruce fu      20017-08-20 - Created
# mail   270064522@qq.com
###############################################################
[ -f /etc/init.d/functions ] && . /etc/init.d/functions

###systemctl PATH post file# post存放post文件目录########
post_dir="/home/http/*"

#please uesr input url
read -p "input a True url -- Example: http://www.xxx.xxx :" url_www

echo "$url_www" |grep -i '[a-z.]'|grep '\.'
if [ $? -eq 1 ];then
    echo "please input Correct url Example:http://xxx.xxx.xxx"
    exit 1
 else
    echo " URL Ture start ab web server test"
fi
function getdir(){
    for element in `ls $post_dir`
      do
        dir_or_file="$element"
        /usr/bin/ab -n 1000 -c 1000 -p $dir_or_file -T application/x-www-form-urlencoded $url_www  >>/home/www/post1.josn
      done
}
while : #死循环,循环两小时后,退出
   do
     getdir >> /home/www/post.josn 2>&1
     sleep 2h
     exit 0
 done