[root@VM-17-13-centos server]# cat /server/scripts/Master-salve-monitoring.sh #!/bin/bashset +o posixIPaddr=`ifconfig |grep 10.200.23.13|awk -F " " '{print $2}'`#IPaddr=`ifconfig |grep 192.168.100.201|awk -F " " '{print $2}'`Hostname=`hostname`User="root"Password="zk123\afc"Host="127.0.0.1"Time=$(date "+%Y-%m-%d %H:%M:%S")Logfile="/server/scripts/Mestre_escravo_status.logs"#webhook="https://oapi.dingtalk.com/robot/send?access_token=92b229bb93205a22a9ce4bbc97f16c966332279f9271759f413f93c9f540fcfe"webhook="https://oapi.dingtalk.com/robot/send?access_token=7263909af3197516f50feee7502cf77aea8ccfca1d0859877f9c8121a4d2d530"mysql -u$User -p$Password -e "show slave status\G" -h${Host}|grep -i "running:" >$LogfileSlave_IO_Running=`grep Slave_IO_Running $Logfile| awk ' {print $2}'`Slave_SQL_Running=`grep Slave_SQL_Running $Logfile | awk '{print $2}'`Check_mysql_status() { if [ "$Slave_IO_Running" = "Yes" -a "$Slave_SQL_Running" = "Yes" ] then echo "slave is Running!" >$Logfile # SendMsgToDingding else echo "Slave is not running! " >$Logfile SendMsgToDingding fi}function SendMsgToDingding() {curl $webhook -H 'Content-Type: application/json' -d "{'msgtype': 'text','text': {'content': '告警主题:中免环境MySQL主从状态监控 \n主机地址: $IPaddr\n主机名称: $Hostname \n当前时间: $Time \n当前状态: `cat /server/scripts/Mestre_escravo_status.logs` \n '},'at': {'isAtAll': false}}"}Check_mysql_status您在 /var/spool/mail/root 中有新邮件