Last active
August 17, 2021 22:12
-
-
Save prochor666/f5dc193a1fe01b9bef2c1e2cdbfa4e70 to your computer and use it in GitHub Desktop.
Very basic netwrork statistics
This file contains hidden or 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 | |
# @author [email protected] | |
# | |
# Check stats for alive network devices | |
# RED 1, GREEN 2 and RESET color | |
DEVICEDOWN=$(tput setaf 1) | |
DEVICEUP=$(tput setaf 2) | |
RESET=$(tput sgr0) | |
for DEVICE in $(ls -I "lo" /sys/class/net); | |
do | |
STATEFILE="/sys/class/net/${DEVICE}/operstate" | |
if [[ -f ${STATEFILE} ]]; | |
then | |
STATE="$(cat ${STATEFILE})" | |
if [[ "${STATE}" == "up" ]]; | |
then | |
RXBYTESFILE="/sys/class/net/${DEVICE}/statistics/rx_bytes" | |
TXBYTESFILE="/sys/class/net/${DEVICE}/statistics/tx_bytes" | |
echo "Device ${DEVICE} is ${DEVICEUP}up${RESET}" | |
if [[ -f ${RXBYTESFILE} ]]; | |
then | |
echo "RX (download): $(cat ${RXBYTESFILE})" | |
fi | |
if [[ -f ${TXBYTESFILE} ]]; | |
then | |
echo "TX (upload): $(cat ${TXBYTESFILE})" | |
fi | |
else | |
echo "DEVICE ${DEVICE} is ${DEVICEDOWN}down${RESET}" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment