linux 网卡流量查看shell
一个不错的查看流量的脚本

  1. #!/bin/bash  
  2.  
  3. # test network width  
  4.  
  5. function usage  
  6.  
  7. {  
  8.  
  9.         echo “Usage: $0  “  
  10.  
  11.         echo “    e.g. $0 eth0 2″  
  12.  
  13.         exit 65  
  14.  
  15. }  
  16. if [ $# -lt 2 ];then  
  17. usage  
  18. fi  
  19. typeset in in_old dif_in  
  20. typeset out out_old dif_out  
  21. typeset timer  
  22. typeset eth  
  23.  
  24. eth=$1  
  25. timer=$2  
  26.  
  27. in_old=$(cat /proc/net/dev | grep $eth | sed -e “s/\(.*\)\:\(.*\)/\2/g” | awk ‘ { print $1 }’ )  
  28. out_old=$(cat /proc/net/dev | grep $eth | sed -e “s/\(.*\)\:\(.*\)/\2/g” | awk ‘ { print $9 }’ )  
  29.  
  30. while true  
  31. do  
  32. sleep ${timer}  
  33. in=$(cat /proc/net/dev | grep $eth | sed -e “s/\(.*\)\:\(.*\)/\2/g” | awk ‘ { print $1 }’ )  
  34. out=$(cat /proc/net/dev | grep $eth | sed -e “s/\(.*\)\:\(.*\)/\2/g” | awk ‘ { print $9 }’ )  
  35. dif_in=$(((in-in_old)/timer))  
  36. dif_out=$(((out-out_old)/timer))  
  37. echo “IN: ${dif_in} Byte/s OUT: ${dif_out} Byte/s”  
  38. in_old=${in}  
  39. out_old=${out}  
  40. done  
  41. exit 0 

本日志由 flyinweb 于 2009-07-08 15:21:11 发表,目前已经被浏览 5206 次,评论 0 次;

作者添加了以下标签: linux网卡流量

引用通告:http://www.517sou.net/Article/135/Trackback.ashx

评论订阅:http://www.517sou.net/Article/135/Feeds.ashx

相关文章

评论列表

    暂时没有评论
(必填)
(必填,不会被公开)