到新公司要求会Python,自己硬着头皮前进,自己研究,觉得和shell完全就是两个不同的概念。血吧呀
自己写的第一个Python,还有待加强。监控mysql的主从同步状态,还在写报警模块
vim mysqlslave.py
#!/usr/bin/python
#conding=utf8
##mysqlstatus
import MySQLdb
import MySQLdb as mdb
import sys
try:
con = mdb.connect('127.0.0.1', 'root', '123456');
cur = con.cursor(MySQLdb.cursors.DictCursor)
cur.execute('show slave status;')
sql = cur.fetchall()
finally:
if con:
con.close()
if sql[0]['Slave_IO_Running'] == 'Yes' and sql[0]['Slave_SQL_Running'] == 'Yes':
print "Slave_IO_Running:",sql[0]['Slave_IO_Running']
print "Slave_SQL_Running:",sql[0]['Slave_SQL_Running']
print "==="*5
else:
print "Slave_IO_Running:",sql[0]['Slave_IO_Running']
print "Slave_SQL_Running:",sql[0]['Slave_SQL_Running']
print "==="*5
阅读(1756) | 评论(0) | 转发(0) |