hello to everyone, i was wondering if you could help me with a script im working on, it's kind of simple but i dont have a lot experience on unix comands: well, here it is:
you might apreciate the infinite while loop
, it is supossed to be running on the server all day scaning it every 5 minutes and cheking if a host is alive or not, if it isnt it will send an email to the sistems administrator.
the problem here is that when it gets to the if [ $? -ne 0 ], it executes both the if and else commands, i have been reading in several pages and i found a solution to use ping exit commands, however i already read in the unix manual that this exact aplication im trying to make is impossible to do with exit commands, here the page where i read it:
http://www.rt.com/man/ping.8.html
extract from the page
"If ping does not receive any reply packets at all it will exit with code
1. On error it exits with code 2. Otherwise it exits with code 0. This
makes it possible to use the exit code to see if a host is alive or not"
the code:
#sx3v1l_1n51de
#Sistema de Monitoreo de Servidores
#CENCAR
a=1
while (test "$a"!="0")
do
for ipadr in `cat ipadress`
do
ping $ipadr
if [ $? -ne 0 ]
then
echo $ipadr" is alive"
else
echo $ipadr" is dead"
ipadr >> noresponseip
#./strike1
/*strike1 is another script that waits 1 minute and then tries to ping again if it still doesnt answer then sends the email to the admin, strike1 uses the noresponseip file to read the ip that didnt answered
i havent actually tested this part yet, what i want to do exactly is that strike1 checks the bad ip's while the other keeps scanning, im not sure about my impementation, the way i put it, does it executes and ends the ./strike1 script or it just starts it and continues scanning ip'? because i dont want it to stop for a minute an send an email evry time it founds host is not answering..*/
fi
done
done
thank you for your help