darkcloud-tmuxconfig/bwrate

28 lines
530 B
Text
Raw Normal View History

#!/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