标签:python error subjects mysql
对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
本文出自 “刚刚出壳的小鸟” 博客,请务必保留此出处http://qhd2004.blog.51cto.com/629417/1826274
标签:python error subjects mysql
原文地址:http://qhd2004.blog.51cto.com/629417/1826274