#!/bin/bash mysql -e "show slave status\G" > mysql_status.txt array=($(egrep 'Slave_IO_Running|Slave_SQL_Running|Seconds_Behind_Master' mysql_status.txt)) if [[ "${array[1]}" == 'Yes' && "${array[3]}" == 'Yes' ]] then if [ "${array[5]}" -eq 0 ] then echo "MySQL slave running OK!" else echo "MySQL slave is behind master ${array[5]} seconds" fi else echo "MySQL slave sync make error" mail -s "MySQL-Slave Error on `uname -n`" [email protected] fi