1. 程式人生 > >檢測tomcat假死時重新啟動及郵件通知

檢測tomcat假死時重新啟動及郵件通知

curl -i elif grep list send http 計劃 dev tom

腳本內容:

#!/bin/bash
IP=10.78.1.183
PORT=8114
TOMCAT_DIR=/data/tomcat_8114
function send_mail(){
        maillist=(
                zhengwei.liu@xxx
        )
        DATE=`date +‘%F %T‘`
        SUBJECT="${IP}的${PORT}端口發生故障,已自動重啟!"
        CONTENT="時間:${DATE}\n主機:${IP}\n事件:${PORT}端口發生重啟"
        for mail in ${maillist[*]};do
                echo -e "${CONTENT}" | mail -s "${SUBJECT}" $mail
        done
}
declare -i NUM=0
for i in `seq 1 3`;do
        CODE=$(/usr/bin/curl -I -m 10 -o /dev/null -s -w %{http_code}"\n" http://10.78.1.183:8114)
        if [ $CODE == "000"  ];then
                ((NUM++))
        fi
        sleep 3
done
if [ $NUM == 3 ];then
        IS_LIVING=`jps -m -l -v | grep 8114 | wc -l`
        if [ ${IS_LIVING} -eq 1 ];then
                PID=`jps -m -l -v | grep 8114 | awk ‘{print $1}‘`
                kill -9 $PID
                ${TOMCAT_DIR}/bin/startup.sh
        elif [ ${IS_LIVING} -eq 0 ];then
                ${TOMCAT_DIR}/bin/startup.sh
        fi
        send_mail
fi

任務計劃:每5分鐘檢測一次

*/5 * * * * /server/scripts/tomcat/check_8114.sh

檢測tomcat假死時重新啟動及郵件通知