git-svn-id: http://172.17.0.253/svn/soft_pkgs/sys_nicmonitor@1225 09c3743a-b0dd-45d3-b506-aa74c7a2a6ef
19 lines
674 B
Bash
19 lines
674 B
Bash
#!/bin/bash
|
|
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"
|