#!/bin/bash # Choose which network interface to poll and bytes per second at which to represent 100% iface="eth0" maxBytes=100000 # Setup our levels list level=("002" "012" "022" "021" "020" "120" "220" "210" "200") # Work out how many levels we have (level list length) levels=${#level[@]} # Get some starting values and wait to gather data echo "000" > /dev/ledborg lastRx=`cat /sys/class/net/${iface}/statistics/rx_bytes` lastTx=`cat /sys/class/net/${iface}/statistics/tx_bytes` sleep 1 # Loop indefinitely while [ 1 ]; do # Read network statistics rx=`cat /sys/class/net/${iface}/statistics/rx_bytes` tx=`cat /sys/class/net/${iface}/statistics/tx_bytes` bytes=$((($rx - $lastRx) + ($tx - $lastTx))) # Save starting values lastTx=$tx lastRx=$rx # Work out utilisation level util=$((($bytes * $levels) / $maxBytes)) if [ $util -ge $levels ]; then util=$(($levels - 1)) fi # Set colour based on utilisation echo ${level[$util]} > /dev/ledborg # Wait for next gather sleep 1 done