284354749 发表于 2018-10-2 14:14:17

mysql检测脚本

#!/bin/sh  
mysqlProcessNum=`ps -ef|grep mysqld|grep -v grep|wc -l`
  
PortNum=`netstat -lnt|grep 3306|wc -l`
  
MysqlStartUp="/data/3306/mysql"
  
LogPath="/tmp/mysql.log"
  
if [ $PortNum -eq 1 -a $mysqlProcessNum -eq 2 ];then
  
echo "db is running"
  
else
  
$MysqlStartUp start >$LogPath
  
sleep 10;
  
mysqlProcessNum=`ps -ef|grep mysqld|grep -v grep|wc -l`
  
PortNum=`netstat -lnt|grep 3306|wc -l`
  
if [ $PortNum -ne 1 ] && [ $mysqlProcessNum -ne 2 ];then
  
    while true
  
    do
  
      killall mysqld >/dev/null 2>&1
  
      [ $? -ne 0 ] && break
  
      sleep 1
  
    done
  
    $MysqlStartUp start >>$LogPath && status="successfully"||status="failure"
  

  
[ $PortNum -eq 0 ] && $MysqlStartUp start >>/tmp/mysql.log
  
[ $? -eq 0 ] && echo "mysql is started"
  
fi
  
mail -s "mysql startup status is $status" 441009395@qq.com < $LogPath
  
fi


页: [1]
查看完整版本: mysql检测脚本