#!/bin/bash
# Shell script to restart MySQL server if it is killed or not working
# due to ANY causes.
# When script detects mysql is not running (it basically sends ping request
# to MySQL) it try to start using /etc/init.d/mysql script; and it sends an
# email to user indicating the status.
# This script must be run from Cron Job so that it can monitor mysql server.
# For more info visit following url:
# http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/08/linux-mysql-server-monitoring.html
# --------------------------------------------------------------------------
# Copyright (C) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# mysql root/admin username
MUSER="root"
# mysql admin/root password
MPASS="SET-ROOT-PASSWORD"
# mysql server hostname
MHOST="localhost"
#Shell script to start MySQL server i.e. path to MySQL daemon start/stop script.
# Debain uses following script, need to setup this according to your UNIX/Linux/BSD OS.
MSTART="/etc/init.d/mysql start"
# Email ID to send notification
EMAILID="notification@somewhere-corp.com"
# path to mail program
MAILCMD="$(which mail)"
# path mysqladmin
MADMIN="$(which mysqladmin)"
#### DO NOT CHANGE anything BELOW ####
MAILMESSAGE="/tmp/mysql.fail.$$"
# see if MySQL server is alive or not
# 2&1 could be better but i would like to keep it simple and easy to
# understand stuff :)
$MADMIN -h $MHOST -u $MUSER -p${MPASS} ping 2>/dev/null 1>/dev/null
if [ $? -ne 0 ]; then
echo "" >$MAILMESSAGE
echo "Error: MySQL Server is not running/responding ping request">>$MAILMESSAGE
echo "Hostname: $(hostname)" >>$MAILMESSAGE
echo "Date & Time: $(date)" >>$MAILMESSAGE
# try to start mysql
$MSTART>/dev/null
# see if it is started or not
o=$(ps cax | grep -c ' mysqld$')
if [ $o -eq 1 ]; then
sMess="MySQL Server MySQL server successfully restarted"
else
sMess="MySQL server FAILED to restart"
fi
# Email status too
echo "Current Status: $sMess" >>$MAILMESSAGE
echo "" >>$MAILMESSAGE
echo "*** This email generated by $(basename $0) shell script ***" >>$MAILMESSAGE
echo "*** Please don't reply this email, this is just notification email ***" >>$MAILMESSAGE
# send email
$MAILCMD -s "MySQL server" $EMAILID < $MAILMESSAGE
else # MySQL is running :) and do nothing
:
fi
# remove file
rm -f $MAILMESSAGE
分享到:
相关推荐
mysql监控脚本,mysql 宕机自启服务。mysql监控脚本,自启mysql监控脚本,自启
官方支持脚本,用于最新版Cacti 1.1.38监控mysql数据库 5.7
mysql.sock 登陆 监控脚本 ,需要简单更改下脚本登陆 本脚本默认为3306端口,可修改其它脚本复用 需要配合 zabbix 监控模版使用 模版链接 https://download.csdn.net/download/zhangxueleishamo/87681013
linux下检测mysql进程状态脚本,做Mysql主备模式,可以监测mysql数据库允许状态。
利用loadrunner工具编写脚本,监控mysql,在场景运行中可以左证mysql的运行状态
NULL 博文链接:https://hb-yym-929.iteye.com/blog/1176299
- Mysql监控脚本需要修改/opt/zabbix/etc/mysql.conf后才能使用; - Nginx不必修改,但NginxStatus状态服务须和监控脚本中配置的地址和端口一致,默认- Redis监控脚本配合模板使用,极为完善,且支持自动发现多实例...
mysql监控脚本常用命令整理,感兴趣的朋友可以了解下哈
mysql从服务器状态监控脚本,源自官方网
mysql 服务启动与关闭脚本,Windows 批处理,双击启动或者关闭
文章目录开发监控MySQL数据库的脚本httpd的监控脚本 开发监控MySQL数据库的脚本 脚本1: cat check_mysql_01.sh #!/bin/bash echo method1---------------------- if [ `netstat -antlpe|grep 3306|awk -F [ :]+ '{...
以前监控mysql的php脚本的一个Bug
NULL 博文链接:https://stevenfeng.iteye.com/blog/2034821
mysql告警监控shell脚本,实现MySQL的监控
编写的脚本用来监控mysql主从模式 环境: Centos5.6 mysql只做同步指定库,没有同步mysql库用户数据 登陆从服务器mysql,添加验证的用户 grant replication client on *.* to 'nagios'@localhost identified ...
zabbix监控mysql数据库详细配置,含监控mysql脚本;
实现监控LINUX系统下MySQL的主从同步错误,同时辅以邮件通知。
说明:监控脚本在 rhel5 下测试正常,其它版本的linux 系统请自行测试,需要的一些准备工作可以查看这篇文章 代码: 代码如下:#监控mysql 主从复制cat chk_mysql_rep.sh #!/bin/bash # #script_name:chk_mysql_rep....
C#/WInform+DotNetBar实现MySQL一件安装,监控服务状态,开启,关闭,重启服务