If Ping, Then Bling

Jun 19, 2011 12:26


There’s something soothing about a visual heartbeat.

So I was chilling at the Starbucks near me this morning. In fact, I still am right now. It’s pretty sweet that they offer free wifi, but it tends to be laggy and unreliable due to having gobs of leeches like me suckiing it up. I’m often in the middle of waiting for a web page to reload or an ssh session to do something, and I wonder to myself “frick, am I even still connected?”. So I wrote a little script to help keep me from having to think much (my favorite kind of scripts).

I basically wanted a script that would make something blink on my laptop for a moment on each successful return of an ICMP echo request (ping). Sort of a visual heartbeat. While ping is a terrible measure of whether your layer 3 path will support TCP, without a layer 3 path you will get no ping. So it’s good enough. I decided to use the “standby” light, since it wouldn’t be doing a whole lot while the laptop was actually running. Capslock, numlock, etc. It can be any light as long as it typically holds one state or the other. I’m posting a version of the script here that’s much simpler and uses the ThinkPad’s “ThinkLight” as the bling source. I think it’s easier to take away from this script exactly what’s going on and how to modify it to your liking.

I’m actually fairly happy to have been annoyed just enough by the connection at Starbucks to get motivated to write this. As a network engineer I’m constantly on the road trying to connect to this or that, or what I’m doing depends on constant connectivity to thus or thus. Not having to check a bunch of terminal windows for heartbeats will be great.

#!/bin/bash # pingbling.sh - If ping, then bling. # Typically you've got to be root to mess with changing sysfs/proc values if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" exit 1 fi # Script spits out tons of crap if there are no args. saving sanity. if [ -z $1 ] ; then echo "Please supply an IP address or hostname to ping" exit 1 fi while true ; do # we're already seeing the bling from the ping, we don't need stdout too. # dialing in a longish return time since this is a "are we still connected" test # and not a "how fast is my connection" test. ping -c1 -W3 $1 > /dev/null if [ $? -eq 0 ] ; then state_before=$(head -1 /proc/acpi/ibm/light | awk '{ print $2 }') echo "on" > /proc/acpi/ibm/light sleep 0.2 echo "off" > /proc/acpi/ibm/light echo $state_before > /proc/acpi/ibm/light sleep 0.8 fi done exit 0
Originally published at The IggBlog. You can comment here or there.

uncategorized

Previous post Next post
Up