centos 7网速监控脚本

#!/bin/bash
if [ $# -ne 1 ];then
dev="eth0"
else
dev=$1
fi

while :
do
RX1=`/sbin/ifconfig $dev |awk -F " " 'NR==5{print $5+0}'`
TX1=`/sbin/ifconfig $dev |awk -F " " 'NR==7{print $5+0}'`
sleep 1
RX2=`/sbin/ifconfig $dev |awk -F " " 'NR==5{print $5+0}'`
TX2=`/sbin/ifconfig $dev |awk -F " " 'NR==7{print $5+0}'`

#echo "RX2 is $RX2"
#echo "TX2 is $TX2"

((RX=RX2-RX1))
((TX=TX2-TX1))
#echo "RX is $RX"
#echo "TX is $TX"
RKBPS=`echo $RX |awk '{print $1/1024 "KB/S"}'`
TKBPS=`echo $TX |awk '{print $1/1024 "KB/S"}'`
clear
echo -e "\033[31mRX=$RKBPS \t TX=$TKBPS\033[0m"
echo `/sbin/ifconfig $dev |grep "byte"`
done

posted @ 2017-08-02 16:33  遥远的绿洲  阅读(264)  评论(0编辑  收藏  举报