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 "33[31mRX=$RKBPS TX=$TKBPS33[0m"
echo `/sbin/ifconfig $dev |grep "byte"`
done

原文地址:https://www.cnblogs.com/zjd2626/p/7274691.html