qq70191 发表于 2018-8-29 10:44:52

shell脚本监控mysql 数据库连接状态

#!/bin/bash  

  

  
mysql -uroot --execute="show slave status\G" | grep Running | awk -F ":" '{print $2}' > /home/mysqlmon
  
cat /home/mysqlmon | grep No &>/dev/null
  
if [ $? -ne 1 ] ; then
  
    echo `date +"%Y-%m-%d %H:%M:%S"` >/home/mysqlmon_error.log
  
    mysql -uroot --execute="show slave status\G">>/home/mysqlmon_error.log
  
    mysql -uroot --execute="start slave;"
  
    mail -s "MySQL replication is wrong, ip " name1@mail.com,name2@mail.com < /home/mysqlmon_error.log
  
fi


页: [1]
查看完整版本: shell脚本监控mysql 数据库连接状态