guiduan 发表于 2011-6-8 14:08:33

分享一个监控网卡当前带宽的shell脚本

原文地址:http://www.31sky.net/2011/06/08/302.html
在Linux下有很多监控网卡流量、带宽的小工具,其实不用小工具,自己写个shell脚本就可以实现,下面就是这个shell脚本的源代码:

#!/bin/bash
if [ -z "$1" ]; then
      echo
      echo usage: $0 network-interface
      echo
      echo e.g. $0 eth0
      echo
      exit
fi
IF=$1
while true
do
      R1=`cat /sys/class/net/$1/statistics/rx_bytes`
      T1=`cat /sys/class/net/$1/statistics/tx_bytes`
      sleep 1
      R2=`cat /sys/class/net/$1/statistics/rx_bytes`
      T2=`cat /sys/class/net/$1/statistics/tx_bytes`
      TBPS=`expr $T2 - $T1`
      RBPS=`expr $R2 - $R1`
      TKBPS=`expr $TBPS / 1024`
      RKBPS=`expr $RBPS / 1024`
      echo "tx $1: $TKBPS kb/s rx $1: $RKBPS kb/s"
done
保存为netspeed,然后赋予其可执行权限chmod +x netspeed,运行./netspeed eth0(不一定是eth0,是具体情况而定),效果如下:


[ 本帖最后由 guiduan 于 2011-6-8 14:11 编辑 ]

cnweb 发表于 2011-6-8 14:11:23

看看

neverno 发表于 2011-6-8 14:21:54

不过,感谢

李院长 发表于 2011-6-8 14:36:26

不错

ATOM 发表于 2011-6-8 14:37:55

看着还不错。能结合到探针里就好了。

pathletboy 发表于 2011-6-8 14:38:43

之前一直用nload,试试这个怎么样。

chaoren521 发表于 2011-6-8 15:10:44

谢谢分享昨天刚看完你的那个自动换密码的

test100 发表于 2011-6-8 16:59:15

收藏了,各种脚本看来都行。

leelei 发表于 2011-6-8 17:06:32

不错

糕手 发表于 2011-6-8 17:09:12

页: [1] 2
查看完整版本: 分享一个监控网卡当前带宽的shell脚本