[root@db01-51 scripts]# cat check_db.sh #!/bin/bash #remote if [ "`nc -w 2 10.0.0.51 3306 &>/dev/null echo ok|grep ok|wc -l `" -gt 0 ] then echo "MySQL is running" else echo "MySQL is stoped" /etc/init.d/mysqld start fi