Linux Shell脚本实现检测tomcat

发布时间:2022-04-19 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Linux Shell脚本实现检测tomcat脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

Linux Shell脚本检测tomcat并自动重启

后台运行命令 sh xxx.sh &
查看后台任务:jobs
召唤到前台:fg jobs编号

可以删掉while循环的代码放到crontab里面定时执行,可以将脚本直接后台运行,

#!/bin/bash
while [ true ]
do
    url="https://www.js-code.com/";
    httpOK=`curl --connect-timeout 10 -m 60 --head --silent $url | awk 'NR==1{print $2}'`;
    if [ $httpOK == "200" ];then
        tomcat6=`ps -ef | grep tomcat | awk 'NR==1{print $1" "$2;}'`;
        user=`echo $tomcat6 | awk 'NR==1{print $1}'`;
        pid=`echo $tomcat6 | awk 'NR==1{print $2}'`;
        if [ $user != "tomcat" ]; then
            service tomcat6 start;
        else
            kill -9 $pid;sleep 5s;service tomcat6 start;service tomcat6 start;service tomcat6 status;
        fi;
    fi;
    sleep 5m;
done;

以上所述就是本文的全部内容了,希望大家能够喜欢。

脚本宝典总结

以上是脚本宝典为你收集整理的Linux Shell脚本实现检测tomcat全部内容,希望文章能够帮你解决Linux Shell脚本实现检测tomcat所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:Linux