本shell的功能是自动恢复mysql主从错误,是不是感觉非常强大?好吧,直接上代码。
代码如下 | 复制代码 |
#!/bin/sh # check_mysql_slave status ip=eth0 mysql_command=/home/server/mysql/bin/mysql mysql_user=root mysql_pass=123456 mysql_sockfile=/tmp/mysql.sock datetime=`date +"%Y-%m-%d_%H:%M:%S"` mysql_slave_logfile=/home/server/logs/check_mysql_slave.log slave_ip=`ifconfig $ip|grep "inet addr" | awk -F[:" "]+ '{print $4}'` #status=$($mysql_command -u$mysql_user -p$mysql_pass -S $mysql_sockfile -e "show slave status\G" | grep -i "running") Slave_IO_Running=`grep Slave_IO_Running $mysql_slave_logfile| awk ' {print $2}'` Slave_SQL_Running=`grep Slave_SQL_Running $mysql_slave_logfile | awk '{print $2}'` if [ "$Slave_IO_Running" = "Yes" -a "$Slave_SQL_Running" = "Yes" ] then echo "Slave is Running!" else echo " $datetime $slave_ip Slave is not running!" >> $mysql_slave_logfile cat | $mysql_command -u$mysql_user -p$mysql_pass -S $mysql_sockfile << EOF stop slave; SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; start slave; exit EOF fi |
时间: 2024-09-23 14:46:28