运行加网关名

  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