shell 监控mysql状态
2015-10-28 10:26
681 查看
#!/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
#/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
相关文章推荐
- PL/SQL Developer Oracle Instance Client连接远端数据库
- MySQL 主从复制与读写分离概念及架构分析
- 使用 PL/SQL Developer 连接oracle 时报错解决办法
- The CHECK_POLICY and CHECK_EXPIRATION options cannot be turned OFF when MUST_CHANGE is ON. (Microsoft SQL Server,错误: 15128)
- PostgreSQL数据库 OLTP高并发请求性能优化
- PLSQL Developer报“动态执行表不可访问,本会话的自动统计被禁止”的解决方案
- System.DllNotFoundException Unable to load DLL SQLite.Interop.dll解决办法
- MySQL server has gone away
- PLSQL Developer报“动态执行表不可访问,本会话的自动统计被禁止”的解决方案
- Sqoop导mysql库到Hive中com.mysql.jdbc.RowDataDynamic错误解决
- mysql使用load命令 报错:ERROR 13 (HY000): Can't get stat of '/root/mysql/mysql/data/datatotestproc' (Errco
- mybatis sqlmap中property遇到的问题
- 使用 Oracle GoldenGate 在 Microsoft SQL Server 和 Oracle Database 之间复制事务
- MySQL server has gone away
- mysql 第23章 监控
- 32位的PL/SQL developer如何连接64位的ORACLE 11g
- Oracle数据库备份、恢复 - 使用PL/SQL Developer 导入、导出Oracle数据库
- 理解MySQL——架构与概念
- PostgreSQL数据库 OLTP高并发请求性能优化
- MySQL主从架构配置案例