龙空技术网

Shell脚本100例:46 MySQL主从监控邮件报警脚本

运维小笔记 1922

前言:

此刻同学们对“mysql主从脚本”可能比较注意,小伙伴们都想要剖析一些“mysql主从脚本”的相关文章。那么小编在网络上搜集了一些对于“mysql主从脚本””的相关知识,希望大家能喜欢,各位老铁们快快来了解一下吧!

此脚本应该能适应各种各样不同的内外网环境。让脚本也顺便监控下MySQL是否正常运行。Slave机器的IO和SQL状态都必须为YES,缺一不可,这里用到了多重条件判断-a。

shell> check_mysql_slave.sh#!/bin/bash#check MySQL_Slave StatusMYSQLPORT='netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $4}''MYSQLIP='ifconfig eth0|grep "inet addr" | awk -F[:" "]+ '{print $4}''STATUS=$(/usr/local/mysql/bin/mysql -u dbuser -dbpwd123 -S /tmp/mysql.sock -e "show slave status\G" | grep -i "running")IO_env='echo $STATUS | grep IO | awk ' {print $2}''SQL_env='echo $STATUS | grep SQL | awk '{print $2}''if [ "$MYSQLPORT" == "3306" ]then echo "mysql is running"else mail -s "warn!server: $MYSQLIP mysql is down" magedu@gmail.comfiif [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ]then echo "Slave is running!"else echo "####### $date #########">> /data/log/check_mysql_slave.log echo "Slave is not running!" >> /data/log/check_mysql_slave.log mail -s "warn! $MySQLIP_replicate_error" magedu@gmail.com << /data/log/check_mysql_slave.logfi# 建议每10分钟运行一次:shell> crontab -e*/10 * * * * root /bin/sh /root/check_mysql_slave.sh
查看更多

Shell脚本100例:43 shell中echo用法Shell脚本100例:42 IO命令大全

标签: #mysql主从脚本