linux下监控tomcat

linxu下监控tomcat,如果tomcat停止,那么立刻启动tomcat

 

新建脚本,里面键入如下内容

 

#!/bin/sh
DTTERM=`ps -ef |grep tomcat |wc -l`     
rq=`date +%Y-%m`
frq=`date +%Y-%m-%d`
minTime=`date +%H:%M`

tomcatLog=/md/server_log/tomcat/$rq
if [ $DTTERM == 1 ]
    then sh /md/apache-tomcat-6.0.20/bin/startup.sh
    if [ ! -d "$tomcatLog" ]; then
        mkdir -p "$tomcatLog"
    fi

    echo "tomcat restart at $frq $minTime" >> $tomcatLog'/'$frq'.log'
else
    if [ ! -d "$tomcatLog" ]; then
        mkdir -p "$tomcatLog"
    fi
    echo "tomcat ok at $frq $minTime" >> $tomcatLog'/'$frq'.log'
fi

 

加入到crontab中自动启动

 

#授权
chmod 777 /home/xx/server_start.sh

#编辑每隔5分钟运行一次脚本

crontab -e

#会打开编辑脚本,里面键入如下命令
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/xx/server_start.sh

#重新启动crontab服务
/ect/init.d/crond restart

 

你可能感兴趣的:(apache,tomcat,linux,脚本)