darkcloud-tmuxconfig/bwrate

26 lines
573 B
Text
Raw Permalink Normal View History

#!/usr/bin/env bash
2015-02-27 09:22:10 -05:00
timespan=1
2015-02-27 09:22:10 -05:00
[[ -z "$1" ]] && {
printf '%s\n' 'Error: no device specified'
exit 1
2015-02-27 09:22:10 -05:00
}
[[ ! -d "/sys/class/net/$1" ]] && {
printf '%s\n' "No such device: $1"
exit 1
2015-02-27 09:22:10 -05:00
}
2015-02-27 09:22:10 -05:00
br1=$(</sys/class/net/"$1"/statistics/rx_bytes)
bt1=$(</sys/class/net/"$1"/statistics/tx_bytes)
2015-02-27 09:22:10 -05:00
sleep $timespan
2015-02-27 09:22:10 -05:00
br2=$(cat /sys/class/net/"$1"/statistics/rx_bytes)
bt2=$(cat /sys/class/net/"$1"/statistics/tx_bytes)
2015-02-27 09:22:10 -05:00
u_speed=$(( ( ( bt2 - bt1 ) / timespan ) / 1024 ))
d_speed=$(( ( ( br2 - br1 ) / timespan ) / 1024 ))
2015-02-27 09:22:10 -05:00
printf '%s\n' "D ${d_speed}KB/s | U ${u_speed}KB/s"