#!/bin/bash
function usage
{
echo "Usage: $0 "
echo "e.g. $0 eth0 2"
exit 1
}
if [ $# -lt 2 ];then
usage
fi
eth=$1
interval=$2
in_old=$(cat /proc/net/dev | grep -w $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{ print $1 }' )
out_old=$(cat /proc/net/dev | grep -w $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{ print $9 }' )
while true
do
sleep ${interval}
in=$(cat /proc/net/dev | grep -w $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{ print $1 }' )
out=$(cat /proc/net/dev | grep -w $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{ print $9 }')
sub_in=$(( ($in-$in_old)/$interval ))
sub_out=$(( ($out-$out_old)/$interval ))
echo "Recv rate: $((${sub_in}/1024)) KB/s Sent rate: $((${sub_out}/1024)) KB/s "
in_old=${in}
out_old=${out}
done
exit 0
阅读(900) | 评论(0) | 转发(0) |