Skip to content

Instantly share code, notes, and snippets.

@aasmith
Created September 15, 2021 19:28
Show Gist options
  • Save aasmith/80a8d4dcd37182f5e72e19ad2c966051 to your computer and use it in GitHub Desktop.
Save aasmith/80a8d4dcd37182f5e72e19ad2c966051 to your computer and use it in GitHub Desktop.
Linux interface bytes per second using only /proc
#!/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
@aasmith
Copy link
Author

aasmith commented Sep 15, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment