统计每分钟的流量

#!/bin/bash

while   true

        do

                RX=`ifconfig|awk 'NR==7{print$2}' | cut -d ":" -f2`

                TX=`ifconfig|awk 'NR==7{print$6}' | cut -d ":" -f2`

                ZX=`expr $RX + $TX`

        sleep 60

 

#       for i in `seq 120 -1 1`

#               do

#                       echo -n -e "\b$i"

#                       sleep 1

#               done

#               echo    -n -e "\b"

 

                RX1=`ifconfig|awk 'NR==7{print$2}' | cut -d ":" -f2`

                TX1=`ifconfig|awk 'NR==7{print$6}' | cut -d ":" -f2`

                ZX1=`expr $RX1 + $TX1`

        ZPX=`expr $ZX1 - $ZX`

 

#       echo $ZPX

                 if [ $ZPX -ge 3145728 ];then

                               echo "eth0:每秒流量为:`echo"scale=2;$ZPX / 1048576" | bc` M/s";exit 2

                 elif [ $ZPX -ge 2359296 ];then

                               echo "eth0:每秒流量为:`echo"scale=2;$ZPX / 1048576" | bc` M/s";exit 1

                 else

                               echo "eth0:每秒流量为:`echo"scale=2;$ZPX / 1048576" | bc` M/s";exit 0

                 fi

 

 

#                iptables -A INPUT -p tcp--dport 80 -s $IP -j REJECT

#        fi

done


你可能感兴趣的:(shell脚本插件)