#!/bin/sh
TomcatID=$(ps -ef |grep tomcat |grep -w 'tomcat'|grep -v 'grep'|awk '{print $2}')
StartTomcat=tomcat_startup_path
WebUrl=www.xxx.com  #需测试服务
TomcatMonitorLog=monitor_log_path

Monitor()
{
 if [ $TomcatID ]; then
    TomcatServiceCode=$(curl -I -m 10 -o /dev/null -s -w %{http_code}  $WebUrl)
    if [ $TomcatServiceCode -eq 200 ]; then
        echo "tomcat is running......"
    else
        echo "restart,TomcatID--->>$TomcatID"
        kill -9 $TomcatID
        echo "kill -9 tomcat ok"
        sleep 3
        echo "sleep 3 ok, starting Tomcat ..."
        $StartTomcat
        echo "send sms ..."
        curl -d "params" "sms_server_url"
     fi
 else
     echo "tomcat process is no exsit, tomcat restart..."
     $StartTomcat
     curl -d "params" "sms_server_url"
 echo "------------tomcat start success-------------" fi } Monitor>>$TomcatMonitorLog

赋予脚本执行权限   chmod +x xxx.sh   chmod 777 xxx.sh 

加入定时任务

 crontab -e

*/1 * * * * shell_path  每分钟执行

01-13 23:14