[K12OSN] Script for checking if servers are up.

Dimitri Yioulos dyioulos at firstbhph.com
Thu Oct 18 19:29:52 UTC 2007


On Thursday 18 October 2007 2:11 pm, Doug Simpson wrote:
> Thanks to all for the replies. I guess I should clarify what I am
> attempting to do here.
>
> I looked at the programs and etc submitted by all of you and while they are
> probably good at what they do, they don't do what I am wanting to do. The
> references in the script I submitted are for reference only. IP addresses
> are not actual and are actually the servers are on several campuses,
> several LANs and some are even over a WAN. I can ping all of the servers I
> want to use this for from the one I want to run the script on.
>
> When I complete the script and get it running properly, the |mail -s "222 is 
down" me at here.there will be substituted with something like:
> |festival --tts and festival has a hard time speaking IP addresses. The
> | script will audibly announce the name of the server that is down.
>
> This script will be run from a linux server that is on all the time, and
> the script will run in the background whether anyone is logged in or not.If
> a server goes down (ie a ping test fails) it will audibly say something
> like "Please check Room tewnty seven's server. It appears to be down." No
> one must be logged in and watching the script run. It just does it's thing
> silently until it detects a down server. If the script runs continuously in
> a loop, it will keep repeating the message every trip through the script
> until the problem is corrected.
>
> Kinda funny, but I find the audible messages are GREAT for monitoring
> things. If all is well, he's quiet. If there are problems, he lets you know
> about it. I have done similar things with simple cron jobs, but the script
> will be better in this instance, I think.
>
> Doug Simpson
> Technology Specialist
> De Queen Public Schools
> De Queen, AR
> simpsond at leopards.k12.ar.us
>
> >>> "David Hopkins" <dahopkins429 at gmail.com> 10/18/2007 12:43 PM >>>
>
> That is what I would try, but are all your servers on the same
> 192.168subnet? If they have 2 NIC's, shouldn't you be using the other
> interfaces IP
> address instead of the one used for the thin clients?
>
> On 10/18/07, Huck <dhuckaby at paasda.org> wrote:
> > double-replying..
> >
> > $list = 192.168.0.222,192.168.0.223
> >
> > for $x in $list
> > do
> > sleep 30
> > if ping -i 3 -c 3 $x
> > then continue
> > else
> > echo "$x down!" | mail -s "222 down" veewee777 at alltel.net
> > break
> > fi
> > done
> >
> >
> >
> >
> > something like that?
> >
> > Doug Simpson wrote:
> > > I am trying to make a script that will ping servers and if they are
> >
> > down, send a message. If they are up it won't send a message.
> >
> > > The problem I am having is if there are more than one, it won't work.
> > >
> > > Here is a sample of my script:
> > > **********sample begins below*************
> > > while (true)
> > > do
> > > sleep 30
> > > if ping -i 3 -c 3 192.168.0.222
> > > then
> > > continue
> > > else
> > > echo "192.168.0.222 down!" | mail -s "222 down" veewee77 at alltel.net
> > > break
> > > fi
> > > done
> > > **********sample ends above***************
> > >
> > >
> > > If I add a second (or more) to it, it fails to work properly.
> > > **********broken sample begins below********
> > > while (true)
> > > do
> > > sleep 30
> > > if ping -i 3 -c 3 192.168.0.222
> > > then
> > > continue
> > > else
> > > echo "192.168.0.222 down!" | mail -s "222 down" me at here.there
> > > break
> > > fi
> > > if ping -i 3 -c 3 192.168.0.223
> > > then
> > > continue
> > > else
> > > echo "192.168.0.223 down!" |mail -s "223 down" me at here.there
> > > done
> > > ***********broken sample ends above**************
> > >
> > > Obviously a bogus email address, but it is for reference.
> > >  Any ideas?
> > >
> > > Doug
> > >
> > > Doug Simpson
> > > Technology Specialist
> > > De Queen Public Schools
> > > De Queen, AR
> > > simpsond at leopards.k12.ar.us
> > >
<CLIP>

  #!/bin/bash
  cat hostlist |  while read line
  do
  pingcount=$(ping -c 1 $line |grep received|awk -F',' '{print $2}'|
awk '{print $1}')
  if [ $pingcount -eq 0 ]; then
  echo "$line is unreachable. Please check, and reboot, if necessary"|  
mail -s "$line unreachable" myaddress at mydomain.com
  fi
  done

"hostlist can be the ip addresses or hostnames of your servers.

Dimitri

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the K12OSN mailing list