shell脚本 监控mysql主从(主主)并发送189邮箱

脚本原理很简单,先连到mysql里面,并把数据库同步的状态字段Slave_IO_Running,Slave_SQL_Running的值取出来,

如果不是"YES",则同步出现问题,后用mail实现邮件发送功能。若手机开通139或189邮箱,则可实现短信提醒功能。

代码如下:

#!/bin/bash
username='root'
password='123456'
host1="192.168.0.x"
host2="192.168.0.xx"
mailist='[email protected],[email protected]'
mysqlcmd=/usr/local/mysql-5.5.8/bin/mysql
Host1_Slave_IO_Running=`$mysqlcmd -h$host1 -u$username -p$password -e "show slave status \G"|grep Slave_IO_Running|awk -F: '{print $2 }'`
Host2_Slave_IO_Running=`$mysqlcmd -h$host2 -u$username -p$password -e "show slave status \G"|grep Slave_IO_Running|awk -F: '{print $2 }'`
Host1_Slave_SQL_Running=`$mysqlcmd -h$host1 -u$username -p$password -e "show slave status \G"|grep Slave_SQL_Running|awk -F: '{print $2 }'`
Host2_Slave_SQL_Running=`$mysqlcmd -h$host2 -u$username -p$password -e "show slave status \G"|grep Slave_SQL_Running|awk -F: '{print $2 }'`
if [ $Host1_Slave_IO_Running != "Yes" ] || [ $Host1_Slave_SQL_Running != "Yes" ]
then
 mail   -s   "alarm!"  "$maillist"  <

注意:发送的多个邮箱之间要用‘,’逗号隔开,本来写的发送到QQ和公司的邮箱,但系统投递老是失败,发送的邮件被当成垃圾邮件,被系统给remove掉了


你可能感兴趣的:(mysql,邮件,脚本,shell,短信,mysql,linux)