#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
mysql_hostname="-h localhost"
mysql_username="-u root"
mysql_userpass="" #-p pass
email_to="xxxx@xxxx.com"
email_subject="Replication is Down"
tmp_replication_slave_reason_filepath="/tmp/replication_slave_reason.txt"
if [ -f $tmp_replication_slave_reason_filepath ]; then
rm -rf $tmp_replication_slave_reason_filepath
fi
echo "show slave status\G;" |mysql $mysql_username $mysql_hostname $mysql_userpass 2>&1 |grep "Slave_IO_Running: No"
if [ "$?" -ne "1" ]; then
echo "Slave_IO_Running: No" >> $tmp_replication_slave_reason_filepath
fi
echo "show slave status\G;" |mysql $mysql_username $mysql_hostname $mysql_userpass 2>&1 |grep "Slave_SQL_Running: No"
if [ "$?" -ne "1" ]; then
echo "Slave_SQL_Running: No" >> $tmp_replication_slave_reason_filepath
fi
if [ -f $tmp_replication_slave_reason_filepath ]; then
mail -s $email_subject $email_to < $tmp_replication_slave_reason_filepath
echo $tmp_replication_slave_reason_filepath
fi
No comments:
Post a Comment