#!/bin/sh

monitor mysql run

#by zkg 2019-08-05

#下面是多种方式来判断mysql是否启动 #local 监控 #if [ "netstat -lnt |grep 3306|awk '{print $4}'|awk -F: '{print $2}'" = "3306" ] #if [ ps -ef |grep mysql|grep -v grep|wc -l -gt 0 ] #if [ netstat -lntup|grep mysqld|wc -l -gt 0 ] #if [ lsof -i tcp:3306|wc -l -gt 0 ] #remote 监控 if [ nmap 192.168.31.75 -p 3306 2>/dev/null|grep mysql|wc -l -gt 0 ] then echo "mysql is running" else echo "mysql is stopped" /data/mysql/mysql start fi