Hi, I seriously need a help here. I’ve written a shell script to monitor our email system. This email service is part of our cluster system,i.e. when one server of the cluster system is down, the email service will move to another cluster server. I am using NRPE to monitor. All existing Nagios plugins are working fine with NRPE, but my own script. Please help me to take a look at my script. Thank you very mich.
--------here is my scipt---------
#!/bin/ksh
Script to monitor the SunONE Messaging Multiplexor # # $1 - IP Address of the MMP Server in dotted decimal # # [email protected] # # Written: 23Oct03 # Updated: 29Jun05
MAX_TRIES=3 # Maximum attempts to contact MMP
RETRY=10 # Seconds to wait between retry attempts
First test: Does the interface exist?
WC=ifconfig -a | grep inet | awk '{ print $2 }' | grep $1 | wc -l
if $WC -ne 1 ]];
then
exit 1
fi
Second test: Is IMAP bound to the proper interface?
netstat -an | grep “$1.143” | grep LISTEN > /dev/null if $? -ne 0 ]];
then
exit 1
fi
Third test: Is POP3 bound to the proper interface?
netstat -an | grep “$1.110” | grep LISTEN > /dev/null if $? -ne 0 ]];
then
exit 1
fi
#Fourth test: Does the IMAP server respond to a simple query?
success=0
i=0
while $i -le $MAX_TRIES ]];
do
#/usr/local/bin/sock $1 143 $RETRY
/bin/echo “a001 NOOP\na001 LOGOUT” | /usr/local/bin/nc -w $RETRY $1
143 > /dev/null
RC=$?
if $RC -eq 0 ]];
then
success=1
break
fi
sleep $RETRY
i=$(( $i + 1 ))
done
if $success -ne 1 ]];
then
exit 1
fi
#Fifth test: Does the POP3 server respond to a simple query?
success=0
i=0
while $i -le $MAX_TRIES ]];
do
/bin/echo “quit\n” | /usr/local/bin/nc -w $RETRY $1 110 > /dev/null
RC=$?
if $RC -eq 0 ]];
then
success=1
break
fi
sleep $RETRY
i=$(( $i + 1 ))
done
if $success -ne 1 ]];
then
exit 1
fi