sh mysql自动检查运行状态自动重新启动脚本邮件提醒

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh mysql自动检查运行状态自动重新启动脚本邮件提醒相关的知识,希望对你有一定的参考价值。

#!/bin/sh
#cat << EOF
#+--------------------------------------------------------------------------+
#|					   === mysql check===						   |
#+--------------------------------------------------------------------------+
#EOF
PORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}'`
MYSQLIP=`ifconfig eth0|awk '/inet/{print $2}'|cut -c 6-`
while [ `whoami` == "root" ]
do
	if [ "$PORT" == "3306" ];then
		echo "mysql is running......"
	else
		echo "restart mysql"
		redis-cli flushall
		sudo service mysql restart
		sleep 30
		PORT2=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}'`
		if [ "$PORT2" == "3306" ];then
			echo "mysql restart successful......" 
			echo "server: $MYSQLIP ukcnshop mysql is down,but it auto restart mysql!" > /var/log/sumymsg
			mail -s "warn!server: $MYSQLIP	 ukcnshop mysql is restart" 123456789\@qq.com < /var/log/sumymsg
			mail -s "warn!server: $MYSQLIP	 ukcnshop mysql is restart" 123456789\@hotmail.com < /var/log/sumymsg
			mail -s "warn!server: $MYSQLIP   ukcnshop mysql is restart" 123456789\@qq.com < /var/log/sumymsg
		else
			echo "mysql restart failure......"
			echo "server: $MYSQLIP ukcnshop mysql is down,please try to restart mysql!" > /var/log/mymsg
			mail -s "warn!server: $MYSQLIP	 ukcnshop mysql is down" 123456789\@qq.com < /var/log/mymsg
			mail -s "warn!server: $MYSQLIP	 ukcnshop mysql is down" 123456789\@hotmail.com < /var/log/mymsg
			mail -s "warn!server: $MYSQLIP   ukcnshop mysql is down" 123456789\@qq.com < /var/log/mymsg
		fi
	fi
break
done

以上是关于sh mysql自动检查运行状态自动重新启动脚本邮件提醒的主要内容,如果未能解决你的问题,请参考以下文章

sh 在Linux上自动保存所有正在运行的VM的状态的脚本

Linux 设置开机自动运行脚本

我写了个sh脚本文件,如何配置才能实现Suse11系统开机时能自动执行该sh脚本。

springboot-自动重启脚本

sh 使用用户数据(自动运行脚本)在启动时设置Java 8(最新)EC2服务器

mysql 自动检查并启动slave 线程的小方法,提高运维效率