歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Shell應用:監控下載速度

Shell應用:監控下載速度

日期:2017/3/1 10:35:34   编辑:SHELL編程

Shell應用:監控下載速度

事例:

[plain]

  1. #!/bin/bash
  2. # author: madding.lip
  3. # date: 2011.10.08
  4. echo -n "請輸入需要查詢的網卡的接口:"
  5. read eth
  6. echo "你要查詢的網卡接口為"$eth
  7. echo -n "輸入需要等到的時間(秒):"
  8. read sec
  9. echo "你計算的是"$sec"秒內的平均流量"
  10. infirst=$(awk '/'$eth'/{print $1 }' /proc/net/dev |sed 's/'$eth'://')
  11. outfirst=$(awk '/'$eth'/{print $10 }' /proc/net/dev)
  12. sumfirst=$(($infirst+$outfirst))
  13. sleep $sec"s"
  14. inend=$(awk '/'$eth'/{print $1 }' /proc/net/dev |sed 's/'$eth'://')
  15. outend=$(awk '/'$eth'/{print $10 }' /proc/net/dev)
  16. sumend=$(($inend+$outend))
  17. sum=$(($sumend-$sumfirst))
  18. echo $sec"秒內總流量為:"$sum"bytes"
  19. aver=$(($sum/$sec))
  20. echo "平均流量為:"$aver"bytes/sec"
Copyright © Linux教程網 All Rights Reserved