echo -n "请输入需要查询的网卡的接口:"
read eth
echo "你要查询的网卡接口为"$eth
echo -n "输入需要等到的时间(秒):"
read sec
echo "你计算的是"$sec"秒内的平均流量"
infirst=$(awk '/'$eth'/{print $1 }' /proc/net/dev |sed 's/'$eth'://')
outfirst=$(awk '/'$eth'/{print $10 }' /proc/net/dev)
sumfirst=$(($infirst + $outfirst))
sleep $sec"s"
inend=$(awk '/'$eth'/{print $1 }' /proc/net/dev |sed 's/'$eth'://')
outend=$(awk '/'$eth'/{print $10 }' /proc/net/dev)
sumend=$(($inend + $outend))
sum=$(($sumend - $sumfirst))
echo $sec"秒内总流量为:"$sum"bytes"
aver=$(($sum/$sec))
echo "平均流量为:"$aver"bytes/sec"
阅读(1515) | 评论(0) | 转发(0) |