Sponsored Content
Full Discussion: smart script?
Top Forums Shell Programming and Scripting smart script? Post 302251623 by raidzero on Monday 27th of October 2008 02:28:13 PM
Old 10-27-2008
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
 

4 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

smart question

eg. : there is a file - 322 bytes, how can I (or you) view just a half of file (161 bytes)? (3 Replies)
Discussion started by: zylwyz
3 Replies

2. Shell Programming and Scripting

Smart Backup Script

Hello Im pretty new to scripting in linux but am keen to learn. I'm trying to create a backup script similar to a batch script I developed for windows (dos) where the backup is to a usb drive. no problems with the backup process but what I would like to do is automatically remove old files if... (2 Replies)
Discussion started by: TheGacko
2 Replies

3. UNIX for Dummies Questions & Answers

Explain the difference between the commands cd ~smart and cd ~/smart

Is it possible for both commands to work? (1 Reply)
Discussion started by: phunkypants
1 Replies

4. Shell Programming and Scripting

Need smart script !

Hi, I need a script to assign variables the below paths /appl/user_projects/domains/<xxx>/servers/<yyy>/logs Where <xxx> can be any number and name of directories. <yyy> can be another set of any number of names and directories. I want to neglect all the <xxx> and <yyy>... (3 Replies)
Discussion started by: mohtashims
3 Replies
Net::Time(3pm)						 Perl Programmers Reference Guide					    Net::Time(3pm)

NAME
Net::Time - time and daytime network client interface SYNOPSIS
use Net::Time qw(inet_time inet_daytime); print inet_time(); # use default host from Net::Config print inet_time('localhost'); print inet_time('localhost', 'tcp'); print inet_daytime(); # use default host from Net::Config print inet_daytime('localhost'); print inet_daytime('localhost', 'tcp'); DESCRIPTION
"Net::Time" provides subroutines that obtain the time on a remote machine. inet_time ( [HOST [, PROTOCOL [, TIMEOUT]]]) Obtain the time on "HOST", or some default host if "HOST" is not given or not defined, using the protocol as defined in RFC868. The optional argument "PROTOCOL" should define the protocol to use, either "tcp" or "udp". The result will be a time value in the same units as returned by time() or undef upon failure. inet_daytime ( [HOST [, PROTOCOL [, TIMEOUT]]]) Obtain the time on "HOST", or some default host if "HOST" is not given or not defined, using the protocol as defined in RFC867. The optional argument "PROTOCOL" should define the protocol to use, either "tcp" or "udp". The result will be an ASCII string or undef upon failure. AUTHOR
Graham Barr <gbarr@pobox.com> COPYRIGHT
Copyright (c) 1995-2004 Graham Barr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.3 2013-02-26 Net::Time(3pm)
All times are GMT -4. The time now is 09:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy