#!/bin/bash
# test network width
function usage
{
echo "Usage: $0 "
echo " e.g. $0 eth0"
exit 65
}
if [ $# -lt 1 ];then
usage
fi
typeset in in_old dif_in
typeset out out_old dif_out
typeset timer
typeset eth
eth=$1
timer=1
in_old=$(cat /proc/net/dev | grep "$eth:" | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $1 }' )
out_old=$(cat /proc/net/dev | grep "$eth:" | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $9 }' )
sleep ${timer}
in=$(cat /proc/net/dev | grep "$eth:" | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $1 }' )
out=$(cat /proc/net/dev | grep "$eth:" | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $9 }' )
dif_in=$(((in-in_old)/timer/1024))
dif_out=$(((out-out_old)/timer/1024))
echo "IN: ${dif_in} KByte/s OUT: ${dif_out} KByte/s"
in_old=${in}
out_old=${out}
exit 0
阅读(735) | 评论(0) | 转发(0) |