#!/bin/bash
DEV=`nmcli d | grep -P "[^(dis)]connected [^(\(externally\))]" | grep -Po ".*?(?= )" | head -n1`
TX_BYTES=$(cat /sys/class/net/$DEV/statistics/tx_bytes)

TX_KB=`expr $TX_BYTES / 1024`
TX_MB=`expr $TX_KB / 1024`


if [ $TX_MB -ge 1 ]
then
    echo $TX_MB mB/s
elif [ $TX_KB -ge 1 ]
then
    echo $TX_KB kB/s
else
    echo $TX_BYTES B/s
fi
