PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin export JAVA_HOME=/usr/java export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin:/usr/local/pcre/bin:/usr/local/ffmpeg/bin TomcatID=`ps -ef|grep tomcat-5.5|grep -v ‘grep‘|head -1|awk ‘{print $2}‘` StartTomcat=/usr/local/tool/tomcat-5.5/bin/startup.sh Weburl=http://localhost:8080 TomcatMonitorlog=/var/log/TomcatMonitor.log Monitor(){ echo "start check Tomcat .." if [ $TomcatID ];then echo "The TomcatID is $TomcatID" TomcatServerCode=`curl -I $Weburl > /etc/swd/status.txt` Status=`cat /etc/swd/status.txt|head -1|awk ‘{print $2}‘` if [ $Status -eq 200 ];then echo "Tomcat is ok" else echo "Tomcat is error" kill -9 $TomcatID sleep 3 $StartTomcat fi fi } Monitor >> $TomcatMonitorlog
*/5 * * * * /etc/swd/check_tomcat.sh > /dev/null 2>&1
本文出自 “梁恩宇-9527” 博客,请务必保留此出处http://liangey.blog.51cto.com/9097868/1660283
原文地址:http://liangey.blog.51cto.com/9097868/1660283