Skip to content

Instantly share code, notes, and snippets.

@sorz
Created September 4, 2013 17:02
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 sorz/6439801 to your computer and use it in GitHub Desktop.
Save sorz/6439801 to your computer and use it in GitHub Desktop.
Making the LED on router flash with traffic. http://sorz.org/flashled/
#!/bin/sh
#set -x
export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
IFNAME="eth0"
FULLSPEED=1200 # KiB/s
LED='/sys/class/leds/tp-link:blue:system/brightness'
while [ True ]
do
# Get traffic data:
str=$(ifconfig $IFNAME | grep 'RX bytes')
str=${str#*'RX bytes:'}
str=${str%' ('*}
str=${str%' ('*}
now=$((str/1024))
speed=$((now-last))
if [ "$speed" -gt "$FULLSPEED" ] ; then
speed="$FULLSPEED"
fi
last="$now"
# Flash LED:
ratio=`echo "scale=3;$speed/$FULLSPEED*1000"|bc`
ontime=${ratio%'.'*}
offtime=$((1000-ontime))
#echo "$ontime"
if [ "$ontime" -gt "0" ] ; then
echo 255 > "$LED"
msleep "$ontime"
fi
if [ "$offtime" -gt "0" ] ; then
echo 0 > "$LED"
msleep "$offtime"
fi
#sleep 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment