[K12OSN] Script for checking if servers are up.

James P. Kinney III jkinney at localnetsolutions.com
Thu Oct 18 19:12:03 UTC 2007


for address in `cat addresslistfile.txt`
do
isdown=`ping -c 1 -n $address|sed -e 's/\-\-\-//g'| grep -c "0
received"`
if [ "$isdown" = "1" ] 
  then
    now=`date`
    echo "$address is down at $now" | mail -s "$address down" my at me.org
fi
done

The addresslistfile.txt is a simple IP address list with one per line
and no blank line at the end.

On Thu, 2007-10-18 at 12:33 -0500, 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
> 
> 
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>
> 
-- 
James P. Kinney III          
CEO & Director of Engineering 
Local Net Solutions,LLC        
770-493-8244                    
http://www.localnetsolutions.com

GPG ID: 829C6CA7 James P. Kinney III (M.S. Physics)
<jkinney at localnetsolutions.com>
Fingerprint = 3C9E 6366 54FC A3FE BA4D 0659 6190 ADC3 829C 6CA7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://listman.redhat.com/archives/k12osn/attachments/20071018/27ef5939/attachment.sig>


More information about the K12OSN mailing list