Skip to content

Instantly share code, notes, and snippets.

@andli
Created December 16, 2018 18:08
Show Gist options
  • Save andli/c2720bc425569e323925164e43f3e189 to your computer and use it in GitHub Desktop.
Save andli/c2720bc425569e323925164e43f3e189 to your computer and use it in GitHub Desktop.
#!/bin/bash
IF=$1
if [ -z "$IF" ]; then
IF=`ls -1 /sys/class/net/ | head -1`
fi
RXPREV=-1
TXPREV=-1
echo "Listening $IF..."
while [ 1 == 1 ] ; do
RX=`cat /sys/class/net/${IF}/statistics/rx_bytes`
TX=`cat /sys/class/net/${IF}/statistics/tx_bytes`
if [ $RXPREV -ne -1 ] ; then
let BWRX=$RX-$RXPREV
let BWTX=$TX-$TXPREV
echo "Received: $BWRX B/s Sent: $BWTX B/s"
fi
RXPREV=$RX
TXPREV=$TX
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment