您的位置:首页 > 数据库 > MySQL

检查mysql错误日志并发邮件通知

2016-07-14 10:26 375 查看
对mysql的错误日志进行检查,如果发现有ERROR,则发送邮件通知。脚本没对错误日志进行处理,因此重复检查还会发送,请大家自行对错误日志进行处理。
代码如下:
#!/usr/bin/python
import sys
import os
import send_mail_lib

f=open('/data/mysql3306/BJ-CSK-0-135.err')
of=open('135-mysql-error.txt','w')

for i in f.readlines():
if "ERROR" in i:
print i,
of.write(i)
f.close()
of.close()

to_list='lluser@163.com;lladmin@163.com'
subjects='mysql on 135 have something error'
size = os.path.getsize('135-mysql-error.txt')

if size!=0:
f=open('135-mysql-error.txt')
m = send_mail_lib.syk_mail('smtp.163.com','lladmin@163.com', 'xxxxxxxx')
i= f.readlines()
contents=''.join(i)
m.sendmailattach(to_list,subjects,contents,"135-mysql-error.txt")
f.close()

#end of scripts
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql error subjects