zootweller
Technical User
The following script sends an email if certain processes have failed, but sends no email if no error is reported.
This works great when ran manually, but for some reason when I add this to run under crontab it will trigger the email event anyway - sending it to the recipient address (not local root).
crontab entry: 5,20,35,50 * * * *
/<location>/healthcheck.ksh > /dev/null 2>&1
Script:
#!/bin/ksh
#
MACHINE=$(uname -n)
# Count iPlanet & SiteMinder processes
IPLANETPROCS=$(ps -ef|grep iplanetws|grep -v grep|wc -l)
SMPROCS=$(ps -ef|egrep "smservauth|smservaz|smservacct|smservadm"|grep -v 'grep'|wc -l)
# SETUP THE FIRST 2 LINES OF THE MAIN REPORT
#
echo "---------------------- Error Alert ---------------------: " > errorreport
echo " " >> errorreport
#
# APPEND TO REPORT IF IPLANET NOT RUNNING
if [ $IPLANETPROCS -lt 1 ]
then
echo "iPlanet web service has failed on $MACHINE" >> errorreport
echo " " >> errorreport
echo " " >> errorreport
fi
#
# ADD TO REPORT IF ANY OF THE 4 SM PROCESSES HAVE FAILED
if [ $SMPROCS -ne 4 ]
then
echo "SiteMinder Process failure on $MACHINE" >> errorreport
echo " " >> errorreport.$DTSTAMP
echo " " >> errorreport.$DTSTAMP
fi
#
# EMAIL THE MAIN REPORT ONLY IF CONTENT HAS BEEN ADDED BEYOND THE FIRST 2 LINES
CHECKMSG=$(more errorreport.$DTSTAMP|wc -l)
if [ $CHECKMSG -gt 2 ]
then
cat errorreport|mailx -r <sender@test.com> -s "Error report - $MACHINE" <recipient@test.com>
fi
Any help will be most welcome!
This works great when ran manually, but for some reason when I add this to run under crontab it will trigger the email event anyway - sending it to the recipient address (not local root).
crontab entry: 5,20,35,50 * * * *
/<location>/healthcheck.ksh > /dev/null 2>&1
Script:
#!/bin/ksh
#
MACHINE=$(uname -n)
# Count iPlanet & SiteMinder processes
IPLANETPROCS=$(ps -ef|grep iplanetws|grep -v grep|wc -l)
SMPROCS=$(ps -ef|egrep "smservauth|smservaz|smservacct|smservadm"|grep -v 'grep'|wc -l)
# SETUP THE FIRST 2 LINES OF THE MAIN REPORT
#
echo "---------------------- Error Alert ---------------------: " > errorreport
echo " " >> errorreport
#
# APPEND TO REPORT IF IPLANET NOT RUNNING
if [ $IPLANETPROCS -lt 1 ]
then
echo "iPlanet web service has failed on $MACHINE" >> errorreport
echo " " >> errorreport
echo " " >> errorreport
fi
#
# ADD TO REPORT IF ANY OF THE 4 SM PROCESSES HAVE FAILED
if [ $SMPROCS -ne 4 ]
then
echo "SiteMinder Process failure on $MACHINE" >> errorreport
echo " " >> errorreport.$DTSTAMP
echo " " >> errorreport.$DTSTAMP
fi
#
# EMAIL THE MAIN REPORT ONLY IF CONTENT HAS BEEN ADDED BEYOND THE FIRST 2 LINES
CHECKMSG=$(more errorreport.$DTSTAMP|wc -l)
if [ $CHECKMSG -gt 2 ]
then
cat errorreport|mailx -r <sender@test.com> -s "Error report - $MACHINE" <recipient@test.com>
fi
Any help will be most welcome!