[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
网友评论