This is a simple script that gets RX / TX values of an interface from /sys pseudo filesystem and calculate difference between current and old values displaying a bandwidth output for kilobytes per second.
Code:
#!/bin/bash
INT="1" # every INT seconds
while true
do
RX1=`cat /sys/class/net/$1/statistics/rx_bytes`
TX1=`cat /sys/class/net/$1/statistics/tx_bytes`
sleep $INT
RX2=`cat /sys/class/net/$1/statistics/rx_bytes`
TX2=`cat /sys/class/net/$1/statistics/tx_bytes`
TXBPS=`expr $TX2 - $TX1`
RXBPS=`expr $RX2 - $RX1`
TXKBPS=`expr $TXBPS / 1024`
RXKBPS=`expr $RXBPS / 1024`
echo "TX $1: $TXKBPS kb/s RX $1: $RXKBPS kb/s"
done
This is a simple script that gets RX / TX values of an interface from /sys pseudo filesystem and calculate difference between current and old values displaying a bandwidth output for kilobytes per second.
[code]
#!/bin/bash
INT="1" # every INT seconds
while true
do
RX1=`cat /sys/class/net/$1/statistics/rx_bytes`
TX1=`cat /sys/class/net/$1/statistics/tx_bytes`
sleep $INT
RX2=`cat /sys/class/net/$1/statistics/rx_bytes`
TX2=`cat /sys/class/net/$1/statistics/tx_bytes`
TXBPS=`expr $TX2 - $TX1`
RXBPS=`expr $RX2 - $RX1`
TXKBPS=`expr $TXBPS / 1024`
RXKBPS=`expr $RXBPS / 1024`
echo "TX $1: $TXKBPS kb/s RX $1: $RXKBPS kb/s"
done
[/code]