ITPub博客

首页 > 数据库 > MySQL > mysql实例日志报错自动发送邮件功能

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

原创 MySQL 作者:jacobxian 时间:2015-02-02 22:55:02 0 删除 编辑
#!/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/,如需转载,请注明出处,否则将追究法律责任。

上一篇: mysqldump备份脚本
请登录后发表评论 登录
全部评论

注册时间:2014-07-16

  • 博文量
    18
  • 访问量
    40152