View linux traffic code in real time

Source: Internet
Author: User
#! /Bin/bashwhile [& quot; 1 & quot;] doeth = $1 RXpre = $ (cat/proc/net/dev | grep $ eth | tr: & quot; & n
 
 
  1. #!/bin/bash  

  2. while [ "1" ]  

  3. do  

  4. eth=$1  

  5. RXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}')  

  6. TXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}')  

  7. sleep 1  

  8. RXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}')  

  9. TXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}')  

  10. clear  

  11. echo  -e  "\t RX `date +%k:%M:%S` TX"  

  12. RX=$((${RXnext}-${RXpre}))  

  13. TX=$((${TXnext}-${TXpre}))  

  14. if [[ $RX -lt 1024 ]];then  

  15. RX="${RX}B/s"

  16. elif [[ $RX -gt 1048576 ]];then  

  17. RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')  

  18. else  

  19. RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')  

  20. fi  

  21. if [[ $TX -lt 1024 ]];then  

  22. TX="${TX}B/s"

  23. elif [[ $TX -gt 1048576 ]];then  

  24. TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')  

  25. else  

  26. TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')  

  27. fi  

  28. echo -e "$eth \t $RX   $TX "  

  29. done  

 

 

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.