mysql的监控脚本
时间:2007-12-13 来源:spyman
前不久去QQ面试,要我写个mysql的监控脚本,要求root用户运行,每十秒种检查一下该服务是否正常.当时没用过sleep命令,没写出来.今天无聊,把这个整理了一下.
while [ "$UID" -eq 0 ]
do
PORT=`netstat -na |grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}'`
if [ $PORT == 3306 ]
then
echo "mysql is running"
else
echo "mysql is stopping"
/etc/rc.d/init.d/mysqld restart
fi
sleep 10
done
do
PORT=`netstat -na |grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}'`
if [ $PORT == 3306 ]
then
echo "mysql is running"
else
echo "mysql is stopping"
/etc/rc.d/init.d/mysqld restart
fi
sleep 10
done
相关阅读 更多 +