主从同步检查脚本

来源:互联网 发布:劲舞团淘宝代理 编辑:程序博客网 时间:2024/06/04 19:28
#!/bin/bash
mysql_cmd="mysql -uroot -p1234567 -S /tmp/mysql.sock"
errorno=(1158 1159 1008 1007 1062)     #数值定义错误号  这些错误号要跳过

while true;do
    array=(`$mysql_cmd -e ("show slave status\G" | egrep '_Running:|Seconds_Behind|Last_SQL_Errno' |awk '{print $NF}')`)
    if [ ${array[0]} = "Yes" ] && [ ${array[1]} = "Yes" ] && [ ${array[2]} = "0" ]; then
        echo "mysql slave is ok"
    else
        for(( i=0; i<${#errorno[$i]}; i++ )); do
            if [ ${array[3]} = "${errorno[$i]}" ]; then
                $mysql_cmd -e "stop slave;set global sql_slave_skip_counter=1;start slave;"
            fi
        done
        char= "mysql slave is not ok"
        echo "$char"
        echo "$char" | mail -s "$char" xxxx@qq.com
    fi
    sleep 30
done
0 0
原创粉丝点击