#!/bin/bash
#configuration
slave_host='localhost'
slave_port='3306'
slave_user='root'
slave_password='123456'
my_command='/usr/bin/mysql'
io_ok="Slave_IO_Running: Yes"
sql_ok="Slave_SQL_Running: Yes"
Behind_Master_NULL="Seconds_Behind_Master: NULL"
###############################
##function
#sebd Email
send_mail(){
mail -s "Slave status" [email protected] << EOF
$io_status
$sql_status
$Behind_Master_Status
EOF
}
#get slave status
result=$($my_command -h"$slave_host" -P"$slave_port" -u"$slave_user" -p"$slave_password" -e 'show slave status\G')
io_status=$(echo "$result" | grep "Slave_IO_Running:")
sql_status=$(echo "$result"|grep "Slave_SQL_Running:")
Behind_Master_Status=$(echo "$result" | grep "Seconds_Behind_Master")
if [[ $io_ok || $sql_ok || $Behind_Master_Status=$Behind_Master_NULL ]]
then
send_mail
fi
|