mysql实例日志报错自动发送邮件功能

#!/bin/bash
##monitoring the mysql performance status ##
##created by jacobxian 20150114##
##script in /home/mysql/scripts/error_alert/error_alert.sh  ##
##WORKPATH="/home/mysql/scripts/error_alert"
##mkdir -p ${WORKPATH}
#set -x


##start set environment
WORKPATH="/home/mysql/scripts/error_alert"
LOGPATH="/home/mysqlapp/mysqllog/logfile"
DATE=`date +"%Y%m%d"`


MAIL_LIST="xianyezhao@richinfo.cn"
MAIL_BIN="/home/crond/bsmtp"
MAIL_IP="192.168.219.34"
##end set environment


##sent mail slow log report for last day
my_sentmail()
{
   echo " " | ${MAIL_BIN} -f `hostname`@139.com -h smtp.api.localdomain -s "${MAIL_IP}:Mysql Error Log Report "  ${MAIL_LIST}  < ${WORKPATH}/report/report_error_tail_${DATE}.log
}
##end sent mail slow log report for last day


##start monitor
cd ${LOGPATH}
ERROR_TIME=`stat mysql-err.log|grep Change`
ERROR_LASTTIME=`cat ${WORKPATH}/mysql_err_change_lasttime.log`
if [ "${ERROR_TIME}" != "${ERROR_LASTTIME}" ] ; then
   tail -100 mysql-err.log >> ${WORKPATH}/report/report_error_tail_${DATE}.log
fi


##log current time to the log file
stat mysql-err.log|grep Change>${WORKPATH}/mysql_err_change_lasttime.log


##send error alert mail to dba
my_sentmail


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29114615/viewspace-1424391/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29114615/viewspace-1424391/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值