mkdir -p /opt/scripts/
cd /opt/scripts/
touch MySQL_slave_status.sh
chmod 744 MySQL_slave_status.sh
vim MySQL_slave_status.sh
#!/bin/sh
# grant select,process,replication client on *.* to 'YLmonitor'@'%' identified by 'monitor';
#*/5 * * * * /opt/scripts/MySQL_slave_status.sh
MYSQL_BIN=/u01/app/mysql/db/bin/mysql
USER=YLmonitor
PASSWORD=monitor
T_ServerId=278
HOST=192.168.111.210
BackPostUrl=xxx
SLAVE_STATUS=(`$MYSQL_BIN -u$USER -p$PASSWORD -h$HOST -e "show slave status\G" | egrep -i "Slave_IO_Running|
Slave_SQL_Running|Seconds_Behind_Master|Slave_SQL_Running_State" |awk -F':' '{print $2}'`)
Slave_IO_Running=${SLAVE_STATUS[0]}
Slave_SQL_Running=${SLAVE_STATUS[1]}
Seconds_Behind_Master=${SLAVE_STATUS[2]}
#状态回传到统一管理中心
curl -d "T_ServerId=${T_ServerId}&IO_Running=${Slave_IO_Running}&SQL_Running=${Slave_SQL_Running}&Seconds_Behind_Master=
${Seconds_Behind_Master}" ${BackPostUrl} >/dev/null 2>&1