Save the following script as an executable script file, for example, called traff.sh.
1, this script can be customized to view the interface, accurate to decimal, and can be flexibly displayed according to the traffic size units.
2. The acquisition interval for this script is 1 seconds.
3, this script does not need to install additional software, can be in emergency situations, such as temporarily want to see if there is a flow through, about how much.
4, some traffic viewing software due to the accuracy of the calculation is different, so the value displayed with this script is not consistent, the display results of this script is compared with Du meter, the difference is very small. There is also the transmission tool itself shows the transmission speed is not accurate.
To use:
1, chmod +x./traff.sh change the file to an executable script.
2,./traff.sh eth0 can start monitoring the interface eth0 traffic, press CTRL + C to exit.
#!/bin/bashwhile ["1"]doeth=$1rxpre=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ') txpre=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ') Sleep 1rxnext=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ') txnext=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ') Clearecho -e "\ t RX ' date +%k:%m:%s ' TX" rx=$ ((${rxnext}-${rxpre})) tx=$ ((${txnext}-${txpre} ) if [[$RX-lt 1024x768]];thenrx= "${rx}b/s" elif [[$RX-gt 1048576]];thenrx=$ (echo $RX | awk ' {print $1/1048576 "MB/S"} ') E lserx=$ (echo $RX | awk ' {print $1/1024 "kb/s"} ') fi if [[$TX-lt 1024x768]];thentx= "${tx}b/s" elif [[$TX-gt 1048576]];thent x=$ (echo $TX | awk ' {print $1/1048576 "MB/S"} ') elsetx=$ (echo $TX | awk ' {print $1/1024 "kb/s"} ') fi echo-e "$eth \ t $RX
$TX "Done
Real-time view of Linux network card traffic