教你學會查看Linux網口流量的步驟

來源:互聯網
上載者:User

Linux的發展迅速,在短短的時間裡已經趕上了微軟,讓微軟也重視了這個對手,也許你在學習Linux,這裡講解查看Linux網口流量的指令碼問題,希望能學會查看Linux網口流量指令碼的知識。通過本指令碼,發現bash確實在算術運算方面比老的shell要強大,為此需要開始學習bash,以利用它強大的功能。不過bash中的for語句功能和c中差異比較大。

  1. # cat stream   
  2.  
  3. #! /bin/bash  
  4. # Write by Neil.xu  qq:37391319 email: xurongzhong@gmail.com  
  5. # 2008-8-19 we need to monitor streams of LTS channels, so write this script  
  6. typeset in in_old dif_in dif_in1 dif_out1  
  7. typeset out out_old dif_out  
  8.  
  9. in_old=$(cat /proc/net/dev | grep eth0 | sed  's=^.*:==' | awk '{ print $1 }' )  
  10. out_old=$(cat /proc/net/dev | grep eth0 | sed  's=^.*:=='  | awk '{ print $9 }')  
  11.  
  12. while true  
  13. do  
  14.          sleep 1  
  15.          in=$(cat /proc/net/dev | grep eth0 | sed  's=^.*:=='  | awk '{ print $1 }')  
  16.          out=$(cat /proc/net/dev | grep eth0 | sed  's=^.*:=='  | awk '{ print $9 }')  
  17.          dif_in=$((in-in_old))  
  18.          dif_in1=$((dif_in * 8 / 1024 / 1024 ))  
  19.          dif_out=$((out-out_old))  
  20.          echo "                                         IN: ${dif_in} bytes     OUT: ${dif_out} bytes "  
  21.          dif_out1=$((dif_out * 8 / 1024 / 1024 ))  
  22.          echo "IN: ${dif_in1} mbps    OUT: ${dif_out1} mbps"  
  23.          in_old=${in}  
  24.          out_old=${out}  
  25. done  
  26.  
  27. 運行效果:  
  28. # ./stream   
  29.                                                 IN: 349179 bytes     OUT: 1363936 bytes   
  30. IN: 2 mbps    OUT: 10 mbps  
  31.                                                 IN: 349612 bytes     OUT: 1361852 bytes   
  32. IN: 2 mbps    OUT: 10 mbps  
  33.                                                 IN: 348684 bytes     OUT: 1358952 bytes   
  34. IN: 2 mbps    OUT: 10 mbps  
  35.                                                 IN: 349998 bytes     OUT: 1359092 bytes   

這樣學會查看Linux網口流量的方法了。

  1. 淺析Linux作業系統中開源Cisco路由虛擬機器
  2. 詳解三十種Linux發行版本
  3. 學習心得:Linux系統檔案鎖
  4. 闡述Linux擴充檔案系統
  5. 輕鬆的完成Linux建立檔案系統

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.