Information Technology Grimoire

Version .0.0.1

IT Notes from various projects because I forget, and hopefully they help you too.

Net I/O Current Bandwidth

The Script

root@site:~# cat scripts/netiotool.sh
#!/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

The Output

root@site:~# scripts/netiotool.sh
Listening eth0...
Received: 2186 B/s    Sent: 13079 B/s
Received: 66 B/s    Sent: 142 B/s
Received: 166 B/s    Sent: 242 B/s
Received: 840 B/s    Sent: 898 B/s
Received: 690 B/s    Sent: 748 B/s
Received: 631 B/s    Sent: 3035 B/s
Received: 230 B/s    Sent: 342 B/s
Received: 132 B/s    Sent: 236 B/s
Received: 132 B/s    Sent: 236 B/s
Received: 132 B/s    Sent: 236 B/s
Last updated on 7 Oct 2023
Published on 7 Oct 2023