zoukankan      html  css  js  c++  java
  • 监控mysql状态并发送Email

    */10 * * * *  /shell/mysql_status.sh > /dev/null 2>&1

    #!/bin/bash

          port55=`/usr/sbin/lsof -i:3355 | wc -l`
          if test $port55 != 0
            then
            echo "$(date +%F-%T) xxx.xxx.xxx.xxx MySQL status runing!!" >> /shell/mysql_status.log
             else
             echo "$(date +%F-%T) xxx.xxx.xxx.xxx mysql status stop" >> /shell/mysql_status.log
             echo "$(date +%F-%T) xxx.xxx.xxx.xxx mysql status stop" > /shell/mysql_status_err.log
             /bin/mail -s "mysql55" xxxxx@qq.com < /shell/mysql_status_err.log
             fi

          declare -a sync55
          sync55=($(/usr/local/mysql5/bin/mysql -S /tmp/mysql55.sock -uroot -xxxxx -e 'show slave statusG' | grep "Running" | awk '{print $2}'))
          if [ "${sync55[0]}" = "Yes" -a "${sync55[1]}" = "Yes" ]
             then
             echo "$(date +%F-%T) xxx.xxx.xxx.xxx msyql synchronous security" >> /shell/mysql_status.log
             else
             echo "$(date +%F-%T) xxx.xxx.xxx.xxx msyql synchronous failure" >> /shell/mysql_status.log
             echo "$(date +%F-%T) xxx.xxx.xxx.xxx msyql synchronous failure" > /shell/mysql_status_err.log
             /bin/mail -s "mysql55" xxxxx@qq.com < /shell/mysql_status_err.log
             fi
    for i in 31 32 33 36;
    do
          port=`/usr/sbin/lsof -i:33$i | wc -l`
          if test $port != 0
            then
            echo "$(date +%F-%T) 192.168.180.$i mysql status runing!!" >> /shell/mysql_status.log
             else
             echo "$(date +%F-%T) 192.168.180.$i mysql status stop" >> /shell/mysql_status.log
             echo "$(date +%F-%T) 192.168.180.$i mysql status stop" > /shell/mysql_status_err.log
             /bin/mail -s "mysql$i" xxxxxxxxx@qq.com < /shell/mysql_status_err.log
             fi

          declare -a sync
          sync=($(/usr/local/mysql5/bin/mysql -S /tmp/mysql$i.sock -e 'show slave statusG' | grep "Running" | awk '{print $2}'))
          if [ "${sync[0]}" = "Yes" -a "${sync[1]}" = "Yes" ]
             then
             echo "$(date +%F-%T) 192.168.180.$i msyql synchronous security" >> /shell/mysql_status.log
             else
             echo "$(date +%F-%T) 192.168.180.$i msyql synchronous failure" >> /shell/mysql_status.log
             echo "$(date +%F-%T) 192.168.180.$i msyql synchronous failure" > /shell/mysql_status_err.log
             /bin/mail -s "mysql$i" xxxxxx@qq.com < /shell/mysql_status_err.log
             fi
    done

  • 相关阅读:
    【整理】PHP获取客户端真实IP地址详解
    配置百度编辑器变成纯代码编辑器
    Notepad++安装SVN插件
    【CodeBase】【转】php随机生成汉字
    【CodeBase】PHP打印所有用户自定义常量
    php5.3新垃圾回收机制详解
    php脚本cli 模式运行
    php 内存分配新
    php-fpm epoll封装
    火焰图定位dbproxy问题
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/6400805.html
Copyright © 2011-2022 走看看