用户登录
用户注册

分享至

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

  • 作者: 小木头no
  • 来源: 51数据库
  • 2022-08-17
#!/bin/bash
while [ true ]
do
        url="http://www.51sjk.com/Upload/Articles/1/0/323/323452_20220817173100361.jpg";
        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;
软件
前端设计
程序设计
Java相关