Re: Server monitoring script

From: Peter Boosten (niemand_at_nergens.loc)
Date: 04/07/04


Date: Wed, 7 Apr 2004 07:05:05 +0000 (UTC)

on Wed, 07 Apr 2004 at 06:48 GMT, Jess wrote:
> How can I use ping in a shell script to check if a server is responding or
> not?
>
> for example
>
> If get reply from ping -t 5 192.168.0.4 then
>
> do nothing
>
> else
> send email to webmaster@xxx.com
>
> fi
>
> One of my servers keeps crashing, it is a slackware linux server
>
> I want to use one of thre uix servers to check every 20 mionutes if it is up
> and if not, notify by email
>
> Thanks
> Jess
>
>
#!/bin/sh
#
# $Id: conchk,v 1.5 2003/02/02 19:02:04 peter Exp $
#
# Connectivitycheck for multiple hosts
#
# Author: Peter Boosten
#

HOSTS="host1 host2"

for host in ${HOSTS}; do
  status=`ping -c 2 ${host} > /dev/null && echo 1`
                if [ "${status}" = 1 ]; then
                        if [ -f /tmp/${host}.not ]; then
                                rm /tmp/${host}.not
                                echo "${host} online again `date '+%H:%M %d-%m-%y'`" \
                                | mail -s "connectivity update" peter
                        fi
                else
                        if [ -f /tmp/${host}.not ]; then
                                echo "do nothing" > /dev/null
                        else
                                touch /tmp/${host}.not
                                echo "${host} offline on `date '+%H:%M %d-%m-%y'`" \
                                | mail -s "CONNECTIVITY ALERT" peter
                        fi
                fi
done

Regards, Peter

-- 
Monday is an awful way to spend one seventh of your life.
MSN/Mail: pboosten at hotmail dot com


Relevant Pages

  • TalkTalk Broadband
    ... Thank you Jess for your suggestions. ... Configuration details use the term Primary name server, ... NetFS - off (No other machines are in the network) ... Resolver and host name - Host name: ...
    (comp.sys.acorn.networking)
  • Re: Reaktionszeit Exchange 2000
    ... der server hat 2 GB RAM und im AD sind 400 User angelegt. ... >Hallo Jess, ... >Exchange Server selbst ist die Administration ein Chaos. ...
    (microsoft.public.de.german.exchange2000.general)
  • Re: Accessing newsgroups with TalkTalk?
    ... server, so I've been trying to follow the example of 'Jess', a recent ... I've followed the sunsite instructions carefully, ie entered the username ... if Jess or anyone else who is listening can advise I'd be very grateful. ... neither the address nor webpage in your sig work for me) ...
    (comp.sys.acorn.networking)
  • Accessing newsgroups with TalkTalk?
    ... I'm on TalkTalk and, as their customers discover, TT does not have a news ... server, so I've been trying to follow the example of 'Jess', a recent ... I've followed the sunsite instructions carefully, ie entered the username ... if Jess or anyone else who is listening can advise I'd be very grateful. ...
    (comp.sys.acorn.networking)
  • Re: Server monitoring script
    ... Jess ... >> How can I use ping in a shell script to check if a server is responding ... > # Connectivitycheck for multiple hosts ...
    (comp.unix.shell)