#!/bin/bashcmd= ' mysql -uslave -ppasswd -p3306 -h 192.168.0.72 -be ' status= ' $cmd ' show slave status\g ' seconds_behind_master= ' echo "$status" |awk '/seconds_behind_ Master/{fs= ":";p rint $2} ' read_master_log_pos= ' echo "$status" |awk '/read_master_log_pos/{fs= ":" ;p rint $2} ' exec_master_log_pos= ' echo "$status" |awk '/exec_master_log_pos/{fs= ":";p rint $2 } ' last_io_errno= ' echo "$status" |awk '/last_io_errno/{fs= ":";p rint $2} ' last_sql_errno= ' echo "$status" |awk '/last_sql_errno/{fs= ":";p rint $2} ' slave_io_running= ' echo "$status" |awk '/slave_io_running/{fs= ': ';p rint $2} ' slave_sql_running= ' echo ' $status ' |awk '/slave_sql_ Running/{fs= ":";p rint $2} ' #nagios status:state_ok=0state_warning=1state_critical=2state_unknown= 3state_dependent=4if [ "$Slave _io_running" != "Yes" -o "$Slave _sql_running" != "Yes" ];then echo "slave_io or slave_sql process Exited! last_io_errno: $Last _io_errno last_sql_errno: $Last _sql_errno " exit $STATE _criticalfilater=$[$Read _master_log_pos - $Exec _master_log_pos]if [ $later -ge 100 ];then echo " Read_master_log_pos: $Read _master_log_pos exec_master_log_pos: $Exec _master_log_pos " exit $STATE _warningfiif [ $Seconds _behind_master -ge 30 ];then echo "warning: seconds_behind_master:$ Seconds_behind_master " exit $STATE _warningfiecho " Slave ok-read_master_log_pos: $Read _master_log_pos exec_master_log_pos: $Exec _master_log_pos Seconds_behind_master: $SecondS_behind_master "exit $STATE _OK
MySQL Master backup monitor slave status Nagios script