分类:
2005-12-27 17:13:27
#!/bin/sh
date=`date +%Y-%m-%d [%T]`
tomcat_one=`ps -ef --cols 200 |grep Tomcat_one |awk '{if($3==1)print $3}'`
tomcat_two=`ps -ef --cols 200 |grep Tomcat_two |awk '{if($3==1)print $3}'`
httpd=`ps -ef --cols 200 |grep httpd |awk '{if($3==1)print $0}'|awk '{if($1=="root")print $3 }'`
#tomcat_one
if [ "$tomcat_one" != 1 ]
then
/sbin/service catalina_one.sh start
echo -e "$date: RESTART" >> /root/logs/tom_one.log
else
echo -e "$date: OK" >> /root/logs/tom_one.log
fi
#tomcat_two
if [ "$tomcat_two" != 1 ]
then
/sbin/service catalina_two.sh start
echo -e "$date: RESTART" >> /root/logs/tom_two.log
else
echo -e "$date: OK" >> /root/logs/tom_two.log
fi
#httpd
if [ "$httpd" != 1 ]
then
/sbin/service httpd restart
echo -e "$date: RESTART" >> /root/logs/httpmonitor.log
else
echo -e "$date: OK" >> /root/logs/httpmonitor.log
fi
crontab中加入任务:
#monitor httpd,tomcat
*/30 * * * * sh /root/logs/monitor.sh
* * 1 * * cat /root/logs/tom_two.log >> /root/logs/tom_two.log.bak ; rm /root/logs/tom_two.log
* * 1 * * cat /root/logs/tom_one.log >> /root/logs/tom_one.log.bak ; rm /root/logs/tom_one.log
* * 1 * * cat /root/logs/tom_httpmonitor.log >> /root/logs/tom_httpmonitor.log.bak ; rm /root/logs/tom_httpmonitor.log