Shell应用:监控下载速度


Shell应用:监控下载速度

事例:

[plain]

  1. #!/bin/bash   
  2. # author: madding.lip  
  3. # date: 2011.10.08  
  4.   
  5. echo -n "请输入需要查询的网卡的接口:"  
  6. read eth  
  7. echo "你要查询的网卡接口为"$eth  
  8. echo -n "输入需要等到的时间(秒):"  
  9. read sec  
  10. echo "你计算的是"$sec"秒内的平均流量"  
  11. infirst=$(awk '/'$eth'/{print $1 }' /proc/net/dev |sed 's/'$eth'://')  
  12. outfirst=$(awk '/'$eth'/{print $10 }' /proc/net/dev)  
  13. sumfirst=$(($infirst+$outfirst))  
  14. sleep $sec"s"  
  15. inend=$(awk '/'$eth'/{print $1 }' /proc/net/dev |sed 's/'$eth'://')  
  16. outend=$(awk '/'$eth'/{print $10 }' /proc/net/dev)  
  17. sumend=$(($inend+$outend))  
  18. sum=$(($sumend-$sumfirst))  
  19. echo $sec"秒内总流量为:"$sum"bytes"  
  20. aver=$(($sum/$sec))  
  21. echo "平均流量为:"$aver"bytes/sec"   

相关内容