返回顶部

收藏

读取linux网卡流量的shell脚本

更多
#!/bin/bash
R2=`cat /sys/class/net/$1/statistics/rx_bytes`
T2=`cat /sys/class/net/$1/statistics/tx_bytes`
NUM=100000
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`
        TBPS=`expr $T1 - $T2`
        RBPS=`expr $R1 - $R2`
        TKBPS=`expr $TBPS / 1024`
        RKBPS=`expr $RBPS / 1024`
        #RKBPS1=`echo "scale=3; $RBPS/$NUM"|bc`
        eval `date "+day=%d; month=%m; year=%Y; hour=%H; minute=%M second=%S"`
        INSTFIL4="$hour:$minute:$second"
        echo "$INSTFIL4 tx $1: $TKBPS kb/ rx $RKBPS kb/s "

        R2=`cat /sys/class/net/$1/statistics/rx_bytes`
        T2=`cat /sys/class/net/$1/statistics/tx_bytes`
        sleep 1s
done

标签:shell,linux,网卡

收藏

0人收藏

支持

0

反对

0

发表评论