The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Real smart question Peterh UNIX for Advanced & Expert Users 2 07-25-2005 12:24 PM
Smart Crash Handling d11wtq UNIX for Dummies Questions & Answers 0 07-05-2005 08:35 AM
smart question zylwyz UNIX for Advanced & Expert Users 3 06-30-2005 05:44 PM
compaq smart array 532 farmacy SCO 2 02-18-2004 10:40 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 10-27-2008
raidzero's Avatar
raidzero raidzero is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 60
smart script?

First, I know that's a bad title. I couldn't think of anything short enough. ...

I wrote the following script to let me know when various parts of the network are down. It used to look like this before last weekend when I got over 500 emails about 1 host being down all weekend:

this is in the cron to run every 5 minutes

Code:
#script to ping nodes specified in /home/scripts/watch
#supposed to email me when one does not respond.



while read HOST ; do live=`ping -c4 "$HOST"|wc -l` ; #read IP's and ping them, count the number of lines returned (should be 9 for success, 4 for failure)


if [ $live -eq 4 ] #pretty self-explanatory
then



echo "This is an automatically generated email to let you know that "$HOST" has not responded to a scheduled ping. \n\n`date`\n\n`ping -c1 "$HOST"`\n\n`traceroute "$HOST"`" | mail -s "IPwatch "$HOST" Down!" email@address.com # send a fancy email
fi
done < /home/scripts/watch # read IPs from this file

today I tried to add some smartness to it so that if it already emailed me 5 times to stop sending them every 5 minutes and instead send every hour. I added some bogus hosts into my definition file to test everything out and so far it has not worked as expected. What have I done wrong?








Code:
while read HOST ; do live=`ping -c4 "$HOST"|wc -l` ; 


if [ $live -eq 4 ] 
then

echo "ping failed" >> /home/scripts/ipwatch/$HOST
FAIL=`cat /home/scripts/ipwatch/$HOST | wc -l`
if [ $FAIL -lt 5 ]
then
echo "This is an automatically generated email to let you know that "$HOST" has not responded to a scheduled ping. \n\n`date`\n\n`ping -c1 "$HOST"`\n\n`traceroute "$HOST"`" | mail -s "IPwatch "$HOST" Down!" email@address.com 
fi
MIN=`date | awk '{print$4}' | cut -d ":" -f2,3`
while [ "$MIN" -eq "00:00" ]
do
echo "This is an hourly reminder about $HOST not responding to ping." | mail -s "IPWatch $HOST reminder" posborn@buckheadbeef.com
done
fi
done < /home/scripts/watch

Thanks
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0