Last active
December 24, 2015 15:39
-
-
Save rdkls/6822643 to your computer and use it in GitHub Desktop.
Shell script to display an interface's bandwidth usage (Tx/Rx) every second
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
secs=1 | |
interface=eth0 | |
echo "Displaying bandwidth on $interface every $secs seconds, ctrl-c to stop" | |
rx_bytes_prev=`ifconfig eth1|grep 'RX bytes'| sed -n 's/^\s*RX bytes:\([0-9]*\).*/\1/p'` | |
tx_bytes_prev=`ifconfig eth1|grep 'TX bytes'| sed -n 's/.*TX bytes:\([0-9]*\).*/\1/p'` | |
while [ true ] ; do | |
sleep $secs | |
rx_bytes=`ifconfig eth1|grep 'RX bytes'| sed -n 's/^\s*RX bytes:\([0-9]*\).*/\1/p'` | |
tx_bytes=`ifconfig eth1|grep 'TX bytes'| sed -n 's/.*TX bytes:\([0-9]*\).*/\1/p'` | |
rx_mbps=`echo "scale=2;($rx_bytes - $rx_bytes_prev) * 8 / 1000 / 1000" | bc` | |
tx_mbps=`echo "scale=2;($tx_bytes - $tx_bytes_prev) * 8 / 1000 / 1000" | bc` | |
echo "Rx $rx_mbps Mbps - Tx $tx_mbps Mbps" | |
tx_bytes_prev=$tx_bytes | |
rx_bytes_prev=$rx_bytes | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment