export LANG=zh_CN
./root/.bash_profile
v_dir=/usr/local/Mysql/bin/
v_user=root
v_passwd=123456
v_log=/home/logs
v_times=10if [-d "${v_log}"];then
echo "${v_log} has existed before."
else
mkdir ${v_log}
fi
echo "" > ${v_log}/slave_status.log
echo "" > ${v_log}/slave_status_error.log
count=1
while true
do
Seconds_behind_master=$(${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" | awk -F':' '/Seconds_behind_master/{print $2}')
if [${Seconds_behind_master}!="NULL"];then
echo "slave is ok!"
${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" >> ${v_log}/slave_status.log
break
else
echo "" >> ${v_log}/slave_status_error.log
date >> ${v_log}/slave_status_error.log
echo "" >> ${v_log}/slave_status_error.log
${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" >> ${v_log}/slave_status_error.log
${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" |egrep 'Delete_rows' > /dev/null 2>&1
if [$?=0];then
${v_dir}Mysql -u${v_user} -p${v_passwd} -e "stop slave;SET GLOBAL sql_slave_skip_counter=1;start slave;"
else
${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" |grep 'Last_SQL_Error'
break
fi
let count++
if [$count -gt ${v_times}];then
break
else
${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" >> ${v_log}/slave_status_error.log
sleep 2
continue
fi
fi
done
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9522838/viewspace-2285007/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9522838/viewspace-2285007/