分类:
2010-01-26 20:30:25
使用Shell脚本检查 Exchange Cluster 角色切换
作者:zlj2208
修改日期:2010年01月26日
转载请注明转自http://zlj2208.cublog.cn/
#!/bin/bash #CompanyName City Mail Server Cluster Check #Written by zlj2208 at 20081211 # #Define snmp variable MASTER_IP='172.16.17.114' SLAVER_IP='172.16.17.115' CLUSER_IP='172.16.17.118' SNMP_CMD='/usr/bin/snmpwalk -t1 -r3' COM_STRING='public' MIB_STRING='IP-MIB::ipAdEntAddr' # P_DIR='/home/monitor/app' BIN_DIR=${P_DIR}/bin TMP_DIR=$P_DIR/tmp TMP_FILE=${TMP_DIR}/cluser_check.tmp MAIL_FILE=${TMP_DIR}/cluser_check_mail.txt MAIL_SNMP=${TMP_DIR}/cluser_check_snmp.txt DATE_TIME=`date "+%Y-%m-%d %H:%M:%S"` SCRIPT_NAME="${BIN_DIR}/`basename $0`" LOG_FILE="/home/monitor/app/logs/check_cluster_role.log" TO_MAIL='your-name1@company-name.com;your-name2@company-name.com' FROM_MAIL='serverwarn@company-name.com' role_warn_mail() { CLUSTER_IP_STATUS=`awk '/172.16.17/ {print $NF}' ${TMP_FILE}` cat <<-EOF >${MAIL_FILE} Subject:CompanyName City Mail Server Cluster Role Notice From:${FROM_MAIL} Return-Path:${FROM_MAIL} To:${TO_MAIL} Reply-to:${FROM_MAIL} Content-Type:text/plain;ChartSet=gb2312 Check Time:${DATE_TIME} Mail backend server cluster rule may be change to ${SLAVER_IP} . Pleae login server 172.16.17.118 to check server status. Currnt cluster status: `awk '{print $NF}' ${TMP_FILE}` This mail send by : ${SCRIPT_NAME} EOF /usr/sbin/sendmail -t < ${MAIL_FILE} } snmp_warn_mail() { cat <<-EOF >${MAIL_SNMP} Subject:CompanyName City Mail Server Cluster Role Notice From:${FROM_MAIL} Return-Path:${FROM_MAIL} To:your-name2@company-name.com;your-name1@company-name.com Reply-to:${FROM_MAIL} Content-Type:text/plain;ChartSet=gb2312 Check Time:${DATE_TIME} Mail backend server cluster rule may be donw. Pleae check server status. This mail send by : ${SCRIPT_NAME} EOF /usr/sbin/sendmail -t < ${MAIL_SNMP} } ${SNMP_CMD} -c${COM_STRING} -v2c ${CLUSER_IP} ${MIB_STRING} >${TMP_FILE} 2>/dev/null echo "------------`date +'%F %X'`-------------------" >>${LOG_FILE} cat ${TMP_FILE} >>${LOG_FILE} echo "----------------END-----------------" >>${LOG_FILE} if [ ! -s ${TMP_FILE} ] ; then snmp_warn_mail exit fi grep ${MASTER_IP} ${TMP_FILE} 2>&1 >/dev/null if [ $? -ne 0 ] ; then role_warn_mail else : #echo role ok fi |