Check the MySQL error log and send an email notification if error is found. The script does not process the error log, so repeated checks are sent, so you can handle the error log on your own.
The code is as follows:
#!/usr/bin/pythonimport sysimport osimport send_mail_ Libf=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= ' [email protected]; [email protected] ' 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 ', ' [email protected] ', ' xxxxxxxx ') i= f.readlines () contents= ". Join (i) m.sendmailattach (to_list,subjects,contents, "135-mysql-error.txt") f.close () #end of scripts
This article is from the "just out of the shell of the Birds" blog, please be sure to keep this source http://qhd2004.blog.51cto.com/629417/1826274
Check MySQL error log for concurrent mail notifications