웹서버 포트 무응답시 메일 보내주는 스크립트
2011.11.30 20:36
원문 : http://www.ischo.net -- 조인상 // 시스템 엔지니어
Writer : http://www.ischo.net -- ischo // System Engineer in Replubic Of Korea
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
원문 : http://www.ischo.net -- 조인상 //시스템 엔지니어
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/bin/ksh ###################################################################################### # script by ischo. # http://www.ischo.net # mail:chosim1@naver.com # script description : # Send mail to ${MAILADDR} if ${TARGET_SERVER}'s ${SERVER_PORT} port disabled ###################################################################################### # Environment TARGET_SERVER=x.x.x.x SERVER_PORT=80 SERVER_NAME=www.ischo.net MAILADDR=chosim1@naver.com STIME=`date +%Y%m%d%H%M%S` MTIME=`date +%H:%M` DDATE=`date +%Y%m%d` PROGHOME=/home/admin LOGFILE=${PROGHOME}/webserver.log MAILFILE=${PROGHOME}/mail.txt STATFILE=${PROGHOME}/laststat.txt if [ ! -f ${STATFILE} ]; then echo "0" > ${STATFILE} fi cat /dev/null > ${MAILFILE} # Check Webserver port telnet ${TARGET_SERVER} ${SERVER_PORT} << ! ^] quit ! # Sendmail if port disabled if [ $? -eq 0 ]; then if [ `cat ${STATFILE}` -eq $? ]; then echo "${DDATE} ${MTIME} ${SERVER_NAME}(${TARGET_SERVER}) Webserver Alive" >> ${LOGFILE} else echo "${DDATE} ${MTIME} ${SERVER_NAME}(${TARGET_SERVER}) Webserver port ${SERVER_PORT} Recovered." >> ${LOGFILE} echo "${DDATE} ${MTIME} ${SERVER_NAME}(${TARGET_SERVER}) Webserver port ${SERVER_PORT} Recovered." >> ${MAILFILE} mail -s "${SERVER_NAME}(${TARGET_SERVER}) Webserver Recover Event!" ${MAILADDR} < ${MAILFILE} echo 0 > ${STATFILE} fi else if [ `cat ${STATFILE}` -eq $? ]; then echo "${DDATE} ${MTIME} ${SERVER_NAME}(${TARGET_SERVER}) Webserver Down Detected." >> ${LOGFILE} echo "${DDATE} ${MTIME} ${SERVER_NAME}(${TARGET_SERVER}) Webserver Down Detected." >> ${MAILFILE} echo "------------------------------------------------------------" >> ${MAILFILE} echo "${SERVER_NAME}(${TARGET_SERVER}) Webserver did not respond from ${SERVER_PORT} port check." >> ${MAILFILE} echo "Check ${SERVER_NAME} webserver daemon or OS." >> ${MAILFILE} echo "------------------------------------------------------------" >> ${MAILFILE} mail -s "${SERVER_NAME}(${TARGET_SERVER}) Webserver Down Event!" ${MAILADDR} < ${MAILFILE} echo 1 > ${STATFILE} else echo "${DDATE} ${MTIME} ${SERVER_NAME}(${TARGET_SERVER}) Webserver remain Down stat." >> ${LOGFILE} fi fi