美文网首页
web测试http协议的上传下载测试

web测试http协议的上传下载测试

作者: ALuckyLive | 来源:发表于2020-07-23 16:57 被阅读0次
[root@baiyunfei-002 apptest]# cat rate.sh
#!/bin/bash


read -p "请输入下载的次数:" number

[[ ! $number =~ ^[[:digit:]]+$ ]] && echo "Wrong parameter" && exit

j=0
b=0
filename='test.txt'

dd if=/dev/zero of=./test.txt bs=1024 count=10240 &>/dev/null
if [ $? == 0 ]
   then

       echo "creat test.txt success"
   else
       exit
fi

#上传文件
for ((a=1;a<=$number;a++));do

     start1=$(date +%s)
     curl -T test.txt http://xxx:8888 &>/dev/null
     if [ $? == 0 ]
        then
         end1=$(date +%s)
         difference1=$(( end1 - start1 ))
         size1=`ls -l |grep test.txt |awk -F" " '{print $5}'`
         rate1=$(( size1/difference1/1024 ))
         (( ratesum1+=rate1 ))
         (( b++ ))
     else
         continue
     fi
done
echo  "上传速率总和: $ratesum1"
echo  "success $b"
echo  "上传速率: $(( ratesum1/$b ))KB/s"




#下载文件
for ((i=1;i<=$number;i++));do

     ls |grep test |xargs rm -f
     start=$(date +%s)
     wget http://xxx:8888/test.txt &>/dev/null
     if [ $? == 0 ] && [ -f $filename ]
        then
         end=$(date +%s)
         difference=$(( end - start ))
         size=`ls -l |grep test.txt |awk -F" " '{print $5}'`
         rate=$(( size/difference/1024 ))
         (( ratesum+=rate ))
         rm -rf test.txt
         (( j++ ))
     else
         continue
     fi
done
echo  "下载速率总和: $ratesum"
echo  "success $j"
echo  "下载速率: $(( ratesum/$j ))KB/s"

unset number size1 size rate1 rate difference1 difference a b i j
exit

相关文章

网友评论

      本文标题:web测试http协议的上传下载测试

      本文链接:https://www.haomeiwen.com/subject/oedtlktx.html