hi,
may I suggest you have a while loop script which does a several checks and assign these values to flatfiles. Then followed by 'if' or case conditions which test against these flastfiles. Finally su - someuser whose .profile is modified to fireoff some script.
I have a similiar script but not 'case' which I run nohup'd on my boxes which wakes up every 300 seconds or 5mins to run these tests. If test condition confirms any dead process it will su - "bouncer", a user on my box which has a modified .profile to restart all my apps in proper sequence, otherwise it justs sends email alerts or do nothing just logging to nohup.out. Maybe u can modify it for your purpose.
good luck
#!/bin/sh
X1="datacenter@mydomain.com"
X2="teamlead@mydomain.com"
SUBJECT="Mydomain_Webserver_Status"
#
#
# test conditions
#
while true
do
rm -f /tmp/xb
rm -f /tmp/xn
httpcount=`ps -ef | grep -v grep | grep http | wc -l > /tmp/xb`
javacount=`ps -ef | grep -v grep | grep java | wc -l > /tmp/xn`
#
# First test
if (test `cat /tmp/xb` -gt "500") then
echo "Maxclient breached 500 webserver will be slow on `date`";
echo "Maxclient Breached 500 webserver will be slow on `date`" | mailx -s $SUBJECT $X1 $X2;
else echo "Maxclient is fine";
fi
# Second test
if (test `cat /tmp/xb` -eq "0") then
echo "Http process is zero on `date` restarting webserver";
echo "Http process is zero on `date` restarting webserver" | mailx -s $SUBJECT $X1 $X2;
/usr/bin/su - bouncer;
else echo "webserver running fine Http Count is `ps -ef |grep -v grep | grep http | wc -l`";
fi
#
# Third test
if (test `cat /tmp/xn` -ne "1") then
echo "appserver is dead bouncing webserver on `date`";
echo "appserver is dead bouncing webserver on `date`" | mailx -s $SUBJECT $X1 $X2;
/usr/bin/su - bouncer;
else echo "appserver is fine";
fi
sleep 300
done