> Linux编程 >

shell监控mysql端口是否运行,没有运行自动重启

#!/bin/bash
/etc/init.d/mysqld status &> /dev/null
if [ $? -eq 0 ]
then
        echo "mysql is running"
else
        echo "警告:mysqld服务不可用"
  echo "重启mysql服务:$(/etc/init.d/mysqld restart &> /dev/null)"
  echo "mysql服务是否已经运行:$(ps -ef | grep mysqld)"
fi

(责任编辑:IT)