Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ingmarioalberto/ee6ac9f24f23c76aa0fe7b17da64f093 to your computer and use it in GitHub Desktop.
Save ingmarioalberto/ee6ac9f24f23c76aa0fe7b17da64f093 to your computer and use it in GitHub Desktop.
network monitor without any requirements
#!/bin/bash
#improved from https://www.commandlinefu.com/commands/view/10095/network-traffic-on-nics-in-mbps-without-sar-iperf-etc...
while true; do
[ -z ${TX2} ] && TX2=0
[ -z ${RX2} ] && RX2=0
[ -z ${INTERFACE} ] && INTERFACE=$(ip link | egrep -e '^[0-9]+:' | grep -v 'lo:' | grep -v 'state DOWN'| cut -d " " -f2 | cut -d ":" -f1 | head -n1) && echo "INTERFACE=${INTERFACE}"
RX1=`cat /sys/class/net/${INTERFACE}/statistics/rx_bytes`
TX1=`cat /sys/class/net/${INTERFACE}/statistics/tx_bytes`
DOWN=$(($RX1-$RX2))
UP=$(($TX1-$TX2))
DOWN_Bits=$(($DOWN * 8 ))
UP_Bits=$(($UP * 8 ))
DOWNmbps=$(( $DOWN_Bits >> 20 ))
UPmbps=$(($UP_Bits >> 20 ))
echo -e "RX:${DOWN}\tTX:${UP} B/s | RX:${DOWNmbps}\tTX:${UPmbps} Mb/s"
RX2=$RX1; TX2=$TX1
sleep 1; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment