[SLUG] shell script - best way question

From: Greg Schmidt (slugmail@gschmidt.net)
Date: Wed Aug 01 2001 - 13:42:40 EDT


Road Runner has been giving me fits with intermittent outages the past few
days. WAN link light on "modem" slowly blinks. Sometimes it is down for
hours, sometimes only minutes. Sometimes it is up for hours, sometimes only
minutes. So, I got inspired to try to track it.

I started off with a shell script like this:

#!/bin/bash
#rrt - test road runner script
while [ 1 -lt 2 ]; do #1 should be less than 2 for a good long time.
        date >> t
        ping -v -c 1 tampabay.rr.com >> t
        sleep 30
done

The log of RR outages in the file t was a bit difficult to read. So, I started
using a script like this:

#!/bin/bash
#rrt2 test road runner script
while [ 1 -lt 2 ]; do
   ping -c 1 tampabay.rr.com > /dev/null
   if [ $? -eq 0 ]
   then
      echo -n "up " >> t2
      date >> t2
   else
      echo -n "down " >> t2
       date >> t2
   fi
   sleep 30
done

t2 is much easier to read than t was. It is easy enough to show and explain to
the RR tech when he shows up later. I launch it with ./rrt2 & from a little
directory where it all lives whenever I'm feeling a need to keep an eye on Road
Runner. Maybe someday I would want to back off from 30 seconds to 5 minutes or
so and put the log into a web page, but not right now.

You see above the first 2 shell scripts I've ever written. I can't believe I
stumbled on a way to do this well. So my question... Is there a better way to
do this? The "1 < 2" test looks particularly kludgey. If tampabay.rr.com ages
out of DNS then it is really 3 minutes between log entries, not 30 seconds, as
the DNS request times out instead of just ping. I'm sure the gurus on this
list will spot other problems. I look forward to hearing about them.

Thanks,
Greg



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 18:22:55 EDT