方法一
#!/bin/bash 
#DATE 2013/11/25
#MAIL gccmx@163.com 
#FUNCTION check the mysql status,if not run start mysql. 
#Create by Chenchao Gao 
checkMysql(){ 
        CMDCHECK=`lsof -i:3306 &>/dev/null` 
        Port="$?"
        PIDCHECK=`ps aux|grep mysqld|grep -v grep` 
        PID="$?"
        if [ "$Port" -eq "0" -a "$PID" -eq 0 ];then 
                return 200
        else
                return 500
        fi 
} 
startMysql(){ 
        /etc/init.d/mysqld start 
} 
checkMysql 
if [ $? == 200 ];then 
        echo "Mysql is running..."
else
        startMysql 
        checkMysql 
        if [ $? != 200 ];then 
                while true
                do
                        killall mysqld 
                        sleep 2
                        [ $? != 0 ]&&break
                done 
                startMysql 
        fi 
fi
方法二
#!/bin/bash  
#mysql check  
PORT="0"  
PORT=`netstat -lnt | grep 3306 | wc -l `  
echo $PORT  
if [ $PORT -eq 1 ]  
 then  
    echo "mysql is  running"  
else  
    echo "mysql is not  running"  
    echo "progrome reeady to start mysql "  

sudo service mysql start  
./check_mysql.sh  
fi

转载地址:http://www.linuxidc.com/Linux/2013-11/93333.htm

Linux使用lsyncd实现2个文件夹实时同步

官方文档: https://axkibe.github.io/lsyncd/download/ 1.安装 $ yum install lsyncd $ yum install rsync $ yum install libtermcap-devel ncurses-devel l...

阅读全文

firewall 防火墙常用命令

查看版本 $ firewall-cmd --version 0.4.3.3 help $ firewall-cmd --help 状态 $ firewall-cmd --state running 重载配置 $ firewall-cmd --reload 重新加载...

阅读全文

修改linux centos系统默认时区

方法一 先安装ntpdate: yum install -y ntpdate 再选择一个时间服务器来更新时间: ntpdate time.windows.com 恢复系统时间为utc时间 ln -sf /usr/share/zo...

阅读全文

欢迎留言