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