View linux Nic traffic in real time and save the following script as an executable script file, for example, traff. sh. 1. this script allows you to customize the interface to be viewed, precise to decimal places, and flexibly display the unit according to the traffic volume. 2. the collection interval of this script is 1 second. 3. this script does not require additional software installation. you can view the linux Nic traffic in real time and save the following script as an executable script file, such as traff. sh. 1. this script allows you to customize the interface to be viewed, precise to decimal places, and flexibly display the unit according to the traffic volume. 2. the collection interval of this script is 1 second. 3. this script does not require additional software installation. you can handle it in case of urgent use. for example, you may want to see if there is any traffic passing through, or the approximate amount. 4. some traffic viewing software may not be consistent with the value displayed in this script because of different computing precision. The Display result of this script is slightly different from that of du meter. In addition, the transmission speed displayed by the transmission tool itself is not accurate. Usage: 1. change chmod + x./traff. sh to an executable script. 2../traff. sh eth0 to start monitoring the interface eth0 traffic and press ctrl + c to exit. 01 #! /Bin/bash02while ["1"] 03do04eth = $105 RXpre = $ (cat/proc/net/dev | grep $ eth | tr: "" | awk '{print $2}') 06 TXpre = $ (cat/proc/net/dev | grep $ eth | tr: "" | awk '{print $10}') 07 sleep 108 RXnext = $ (cat/proc/net/dev | grep $ eth | tr: "" | awk '{print $2}') 09 TXnext = $ (cat/proc/net/dev | grep $ eth | tr: "" | awk '{print $10}') 10clear11echo-e "\ t RX 'date + % k: % M: % s' TX "12RX =$ ($ {RXnext}-$ {RXpre}) 13TX =$ ($ {TXnext}-$ {TXpre })) 14 15if [[$ RX-lt 1024]; then16RX = "$ {RX} B/s" 17 elif [[$ RX-gt 1048576]; then18RX = $ (echo $ RX | awk '{print $1/1048576 "MB/s "}') 19else20RX = $ (echo $ RX | awk '{print $1/1024 "KB/s"}') 21fi22 23if [[$ TX-lt 1024]; then24TX = "$ {TX} B/s" 25 elif [[$ TX-gt 1048576]; then26TX = $ (echo $ TX | awk '{print $1/1048576 "MB/s "}') 27else28TX = $ (echo $ TX | awk '{print $1/1024 "KB/s"}') 29fi30 31 echo-e "$ eth \ t $ RX $ TX" 32 done
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service