未来已来

shell脚本实现自动启动mysql服务

上一篇 / 下一篇  2008-10-12 00:25:33 / 个人分类:Shell脚本开发

mysql 停止启动命令如下:

# 启动 MySQL Server
root@localhostroot]#  service mysql start
# 停止 MySQL Server
root@localhostroot]#  service mysql stop
#停止mysql的另类方法
root@localhostroot]#  pkill mysql
#重新启动 MySQL Server
root@localhostroot]#  service mysql restart

根据以上命令实现shell mysql 监控脚本(以下脚本在RH9.0上调试通过)

#!/bin/bash
# ------------------------------------------------------------------------
# Mysql Process Monitor
# Restart MySql Server When It Goes Down
# -------------------------------------------------------------------------
# Copyright (c) 2008http://www.51testing.com
# -------------------------------------------------------------------------

#Mysql start command
restart_mysql="service mysql start"

pgrep="/usr/bin/pgrep"

# mysql daemon name,
mysql_service="mysqld"


# find mysql pid
$pgrep ${mysql_service}


#if mysql is not runnint
if [ $? -ne 0 ];then

 # restart apache
 $restart_mysql

fi


 


TAG: Shell脚本开发

 

评分:0

我来说两句

Open Toolbar