Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1751405
  • 博文数量: 600
  • 博客积分: 10581
  • 博客等级: 上将
  • 技术积分: 6205
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-06 10:13
文章分类
文章存档

2016年(2)

2015年(9)

2014年(8)

2013年(5)

2012年(8)

2011年(36)

2010年(34)

2009年(451)

2008年(47)

分类: LINUX

2014-02-28 09:49:42

#!/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
阅读(874) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~