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

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/bin/bash
while [ true ]
do
        url="http://www.oschina.net/";
        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;