Created
September 15, 2021 19:28
-
-
Save aasmith/80a8d4dcd37182f5e72e19ad2c966051 to your computer and use it in GitHub Desktop.
Linux interface bytes per second using only /proc
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 | |
time="1" # one second | |
int="eth1" # network interface | |
while true | |
do | |
txbytes_old="`cat /sys/class/net/$int/statistics/tx_bytes`" # sent bytes | |
rxbytes_old="`cat /sys/class/net/$int/statistics/rx_bytes`" # recv bytes | |
sleep $time | |
txbytes_new="`cat /sys/class/net/$int/statistics/tx_bytes`" # sent bytes | |
rxbytes_new="`cat /sys/class/net/$int/statistics/rx_bytes`" # recv bytes | |
txbytes="`expr $txbytes_new - $txbytes_old`" # evaluate expressions for sent bytes | |
rxbytes="`expr $rxbytes_new - $rxbytes_old`" # evaluate expressions for recv bytes | |
echo "tx $txbytes bytes/s - rx $rxbytes bytes on interface $int" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted from https://www.unixteacher.org/blog/display-packets-per-second-on-linux/