[原] 获取Linux网络流量脚本
语法:[--help] [-i] [-d]
#!/bin/bash
VERSION="1.0.0.1"
eth=""
sec=0
help()
{
printf "Version: $VERSION \n\
Usage: $0 [-i interface] [-d time]\n\
\t-i|--interface : The needs of the inquiries Interface Network Card (such as eth0, eth1...)\n\
\t-d|--time : Delay time(seconds)\n";
}
echo "$*"
for dummy
do
case $1 in
--help) help; exit 1;;
-i|--interface) shift; eth=$1;;
-d|--time) shift; sec=$1;;
esac
shift
done
#echo -n "Please enter the needs of the inquiries Interface Network Card (such as eth0, eth1...): "
#read eth
echo "Your input data is:"$eth
#echo -n "Input delay time(seconds):"
#read sec
echo "You are calculated within "$sec" seconds of the average flow, Please wait... "
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"(s) total flow is: "$sum" bytes"
aver=$(($sum/$sec))
echo "The average flow is: "$aver" bytes/sec"