监控mysql状态的脚本
# vi mysql.sh
#!/bin/bash
Port=`netstat -ntpl | grep mysqld | awk -F[:" "]+ '{print $5}'`
if [[ $Port == "3306" ]];then
echo "mysql is running at time:`date +%y/%m/%d-%H:%M`" >> /usr/local/apache/logs/mysql.log
else
echo "mysql is down at time:`date +%y/%m/%d-%H:%M`" >> /usr/local/apache/logs/mysql.log
service mysqld restart
fi
:wq
注:写时千万注意空格
本文转自linux博客51CTO博客,原文链接http://blog.51cto.com/yangzhiming/834286如需转载请自行联系原作者
yangzhimingg