darkcloud-tmuxconfig/bwrate
2014-04-09 14:30:31 -04:00

27 lines
530 B
Bash
Executable file

#!/usr/bin/env bash
TIMESPAN=1
if [ -z $1 ]; then
echo "Error: no device specified"
exit 1
fi
if [ ! -d /sys/class/net/$1 ]; then
echo "No such device: $1"
exit 1
fi
BR1=`cat /sys/class/net/$1/statistics/rx_bytes`
BT1=`cat /sys/class/net/$1/statistics/tx_bytes`
sleep $TIMESPAN
BR2=`cat /sys/class/net/$1/statistics/rx_bytes`
BT2=`cat /sys/class/net/$1/statistics/tx_bytes`
DOWNKB=$(((($BR2-$BR1) / $TIMESPAN) /1024))
UPKB=$(((($BT2-$BT1) / $TIMESPAN) /1024))
echo "D ${DOWNKB}KB/s | U ${UPKB}KB/s"
exit 0