监测mysql错误日志,有错误自动邮件报警

#检查错误日志里是否有今天新出现的ERROR或者Warning,有的话,邮件报警
#每个机器生成一个错误日志文件
ErrorLogFile=/data/server/mysql_3307/mysqld.err
LogDir=/data/server/mysql_3307/
#LogFile=/data/server/mysql_3307/err.err
AnalyzeDate=`date +%y%m%d`

HostGroup1=('10.192.200.202' '10.192.200.100')

source='……'
target='……'
MailUser='……'
MailPassword='……'

#true > $LogFile
for host1 in ${HostGroup1[@]}

do
    ssh $host1 cat $ErrorLogFile | grep $AnalyzeDate | grep '\[ERROR\]' > $LogDir$host1.err
    ssh $host1 cat $ErrorLogFile | grep $AnalyzeDate | grep '\[Warning\]' > $LogDir$host1.err
    if test -s $LogDir$host1.err;
    then
        echo  'errors exist in '$host1\''errlog,please check '$LogDir$host1.err' and deal with it!'
	title1=$host1' errlog alert'
        content1='errors exist in '$host1\''errlog,please check '$LogDir$host1.err' and deal with it!'
        /usr/local/bin/sendEmail -f $source -t $target  -s smtp.chinaunicom.cn -u $title1 -xu $MailUser -xp $MailPassword -m $content1
    else
        echo 'there are no errors in the '$host1\''errlog.'
    fi
done


然后编写定时任务即可。


--注意:我原本是这样写的:


写完之后csdn自动给改成这样了:

监测mysql错误日志,有错误自动邮件报警_第1张图片

你可能感兴趣的:(监测mysql错误日志,有错误自动邮件报警)