#!/bin/bash user="root" password="123456" mycmd="mysql -u$user -p$password -h 192.168.100.20" function chkdb() { list=($($mycmd -e "show slave status \G"|egrep "Running|Behind"|awk -F: '{print $2}')) if [ ${list[0]} = "Yes" -a ${list[1]} = "Yes" -a ${list[2]} -lt 120 ] then echo "Mysql slave is ok" else echo "Mysql slave replation is filed" fi } function main() { while true do chkdb sleep 3 done } main