首页 > 数据库技术 > 详细

shell 监控mysql状态

时间:2015-10-28 12:48:52      阅读:270      评论:0      收藏:0      [点我收藏+]


#!/bin/bash 
#/usr/bin/nmap localhost | grep 3306 
#lsof -i:3306 
MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ ‘{print $5}‘` 

function checkMysqlStatus(){ 
/usr/bin/mysql -uroot -paaaaaa --connect_timeout=5 -e "show databases;" &>/dev/null 2>&1 
if [ $? -ne 0 ] 
then 
restartMysqlService 
if [ "$MYSQLPORT" == "3306" ];then 
echo "mysql restart successful......" 
else 
echo "mysql restart failure......" 
echo "Server: $MYSQLIP mysql is down, !" > /var/log/mysqlerr 
#mail -s "WARN! server: $MYSQLIP mysql is down" root@admin < /var/log/mysqlerr 
fi 
else 
echo "mysql is running..." 
fi 


function restartMysqlService(){ 
echo "try to restart the mysql service......" 
/bin/ps aux |grep mysql |grep -v grep | awk ‘{print $2}‘ | xargs kill -9 
service mysql start 


if [ "$MYSQLPORT" == "3306" ] 
then 
checkMysqlStatus 
else 
restartMysqlService 
fi

本文出自 “断了的军刀” 博客,请务必保留此出处http://90sec.blog.51cto.com/7404127/1707140

shell 监控mysql状态

原文:http://90sec.blog.51cto.com/7404127/1707140

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!