speed 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. # IF='eth0'
  3. readonly IF=`ls /sys/class/net/ | grep -E '^wl'`
  4. readonly IVL=3
  5. readonly SPEECH_RATE='--rate -50' # -100<0>100
  6. readonly KB_SCALE=$(( $IVL * 125 )) # bytes => kbits
  7. readonly UP_STATS_FILE=/sys/class/net/$IF/statistics/tx_bytes
  8. readonly DOWN_STATS_FILE=/sys/class/net/$IF/statistics/rx_bytes
  9. if [ "$1" == "--up" ]
  10. then DIR="up" ; STATS_FILE=$UP_STATS_FILE
  11. else DIR="down" ; STATS_FILE=$DOWN_STATS_FILE
  12. fi
  13. if [ "$2" == "--once" ]
  14. then N=1 ; n=0
  15. else N=0 ; n=0
  16. fi
  17. total_bytes=`cat $STATS_FILE`
  18. prev_bytes=$total_bytes
  19. while (( 1 ))
  20. do total_bytes=`cat $STATS_FILE`
  21. bytes=$(( $total_bytes-$prev_bytes ))
  22. kbps=$(( $bytes/$KB_SCALE ))
  23. display_prev_bytes=$prev_bytes
  24. prev_bytes=$total_bytes
  25. rate_msg=$( ( [ $(( $kbps )) -gt $(( 999 )) ] && echo "$(( $kbps/1000 )) mibulz" ) || \
  26. ( [ $(( $kbps )) -gt $(( 99 )) ] && echo "$(( $kbps/100*100 )) kibulz" ) || \
  27. ( [ $(( $kbps )) -gt $(( 9 )) ] && echo "$(( $kbps/10*10 )) kibulz" ) || \
  28. echo "$kbps kibulz" )
  29. clear ; echo -e "$IF $DIR sample[$n]:\n $rate_msg" ; echo "details:" ;
  30. echo " $total_bytes total_bytes"
  31. echo "- $display_prev_bytes prev_bytes"
  32. echo "---------------------------"
  33. echo " $bytes bytes per $IVL secs"
  34. echo " $(( $bytes / $IVL )) bytes/sec" ;
  35. echo " $(( $bytes / $IVL / 8 )) bits/sec" ;
  36. echo " $(( $kbps )) kibbles/sec" ;
  37. sleep $IVL
  38. # (( $N < 1 )) && echo t || echo f
  39. # (( $n < $N )) && echo t || echo f
  40. # (( $N > 0 )) && (( $n >= $N )) && echo t || echo f
  41. # [[ $(( $N <= 1 )) || $(( $n < $N )) ]] && n=$(( $n+1 )) && sleep $IVL || break
  42. speech_msg=$rate_msg
  43. (( $n > 0 )) && spd-say $SPEECH_RATE "$speech_msg" ; n=$(( $n+1 )) ;
  44. (( $N > 0 )) && (( $n >= $N )) && break
  45. done