[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: whats wrong with my internet connection checker script?



On Sun, 26 Dec 2010 23:57:42 +0000
Chris Davies <chris-usenet@roaima.co.uk> wrote:

> S Mathias <smathias1972@yahoo.com> wrote:
> > ping -W 1 -c 4 google.com >& /dev/null | grep "100% packet loss"
> > ping -W 1 -c 4 www.yahoo.com >& /dev/null | grep "100% packet loss"
> 
> > both sides "false", because they have no output, because google.com
> > and www.yahoo.com is reachable.
> 
> Or because your local system is so offline that it's got no way of
> resolving those names to IP addresses.
> 
> I'd recommend you turn your pattern match around to look for any sort
> of success, rather than one specific instance of failure.
> 

I would recommend going further than that: I've often seen a router
pass pings and replies by DNS but not web pages or some other protocols.
My current scripts check for specific strings from up to six websites,
rotating the order each time so one site doesn't get too much traffic.
There is a log kept which I check every month or two to confirm the
sites still contain the strings.

It may seem a bit overengineered, but I made progressively more and more
complex scripts until they worked reliably and without false positives,
and I'm afraid this was the point I reached. They haven't changed for
some years now, nor has the number increased beyond six.

Here's a fragment from script rw1:

logfile="/var/log/routerboot"
echo -e -n `date`  >> $logfile
echo -n " -rw1- "  >> $logfile
count=0
count=$((count+`curl -s www.google.com | grep -c content-type`))
echo -n $count >> $logfile
if [ $count -eq 0 ]
then
  count=$((count+`curl -s www.google.co.uk | grep -c content-type`))
  echo -n $count >> $logfile
  if [ $count -eq 0 ]
  then
.. etc, culminating in router reboot code ...

-- 
Joe


Reply to: