首页 > 系统服务 > 详细

shell脚本监控Tomcat并重启发送短信

时间:2019-09-25 23:43:10      阅读:159      评论:0      收藏:0      [点我收藏+]
#!/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  每分钟执行

shell脚本监控Tomcat并重启发送短信

原文:https://www.cnblogs.com/codechange/p/11588257.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!