本文共 1333 字,大约阅读时间需要 4 分钟。
#!/bin/shPATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/binexport JAVA_HOME=/usr/java/jdk1.6.0_37export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jarexport PATH=$PATH:$JAVA_HOME/binTomcatID=$(ps -ef | grep tomcat|grep -w 'tomcat-7.0.42'|grep -v grep|awk '{print $2}')StartTomcat=/opt/soft/tomcat-7.0.42-linux-pro/bin/startup.shTomcatCache=/opt/soft/tomcat-7.0.42-linux-pro/workWebUrl=https://localhost/GetPageInfo=/tmp/TomcatMonitor.InfoTomcatMonitorLog=/tmp/TomcatMonitor.logMonitor(){ echo "[info]开始监控tomcat...[$(date +'%F %H:%M:%S')]" if [ $TomcatID ];then TomcatServiceCode=$(curl -o $GetPageInfo -s -m 10 --connect-timeout 10 -w %{http_code} -k $WebUrl) if [ $TomcatServiceCode -eq 200 ];then echo "[info]页面返回码为$TomcatServiceCode,tomcat启动成功,测试页面正常......" else echo "[error]tomcat页面出错,请注意......状态码为$TomcatServiceCode,错误日志已输出到$GetPageInfo" echo "[error]页面访问出错,开始重启tomcat" kill -9 $TomcatID sleep 3 rm -rf $TomcatCache $StartTomcat fi else echo "[error]tomcat进程不存在!tomcat开始自动重启..." echo "[info]$StartTomcat,请稍候......" rm -rf $TomcatCache $StartTomcat fi}Monitor>>$TomcatMonitorLog
转载地址:http://uylxx.baihongyu.com/