Linux traffic monitoring script

  

#############Script content is as follows##############

#!/bin/bash ## action: monitoring traffic eth0 port ## may be changed to other ports ## eth0 eth1 oF like: Barlow ## 2012-12-10 # take the initial flow rate value R1 = `cat /sys /class /net /eth0 /Statistics/rx_bytes`T1=`cat /sys/class/net/eth0/statistics/tx_bytes`## Pause for 10 seconds and then take the value again sleep 10R2=`cat /sys/class/net/eth0/statistics/rx_bytes`T2= `cat /sys/class/net/eth0/statistics/tx_bytes`##Calculate the average flow value in 10 seconds in kb/s TBPS=`expr $T2 - $T1`RBPS=`expr $R2 - $R1 ## The following 10240 represents 10 seconds multiplied by 1024TKBPS=`expr $TBPS /10240`RKBPS=`expr $RBPS /10240`echo "Upload rate eth0: $TKBPS kb/s Download rate eth1: $RKBPS kb/s at $(date +%Y%m%d%H:%M:%S)" >> /home/barlow/shell/network_$(date +%Y%m%d).log#### ######## After executing 3 times, the log is as follows ##############

#cat /home/barlow/shell/network_$(date +%Y %m%d).log upload rate eth0: 12 kb/s download rate eth0: 166 kb/s at 2013031912:16:03 upload rate eth0: 10 kb/s Upload rates eth0: 60 kb /s at 2013031912: 16: 39 upload rate eth0: 12 kb /s download rate eth0: 81 kb /s at 2013031912: 17: 14

Copyright © Windows knowledge All Rights Reserved