监控网卡流量shell脚本

 1 #!/bin/bash
 2 #by zhangjia
 3 #date:2019年2月12日14:11:14
 4 #shell name:network_traffic.sh
 5 #监控网卡流量
 6 ##############################################333
 7 while :
 8 do
 9     NETWORK_NAME="ens32"
10     time=`date +%F' '%T`
11     RX_before=`ifconfig ${NETWORK_NAME}|grep bytes|grep RX|awk '{print $3}'`
12     TX_before=`ifconfig ${NETWORK_NAME}|grep bytes|grep TX|awk '{print $3}'`
13     sleep 2
14     #获取2秒后的值
15     RX_after=`ifconfig ${NETWORK_NAME}|grep bytes|grep RX|awk '{print $3}'`
16     TX_after=`ifconfig ${NETWORK_NAME}|grep bytes|grep TX|awk '{print $3}'`
17     #计算2秒之间的茶汁
18     rx_result=$(((${RX_after}-${RX_before})/256))#rx_result=$[(RX_after-RX_before)/256]
19     tx_result=$(((${TX_after}-${TX_before})/256))
20     echo " ${time}  now_in_speed: ${rx_result}kbps Now_Out_speed: ${tx_result}dbps"
21     sleep 2
22 done

 

posted @ 2019-07-16 23:45  zhj5551  阅读(363)  评论(0编辑  收藏  举报