223d4f3de07f52a53bd6f31bba55f552_r.jpg

#!/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

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code