监控keepalived的shell脚本参考
#!/bin/bash
while true
do
counter=$(netstat -na|grep "LISTEN"|grep "3306"|wc -l)
if [ "${counter}" -eq 0 ]; then
#echo "no mysql process";
continue;
else
counter2=$(netstat -na|grep "LISTEN"|grep "/usr/sbin/keepalived"|wc -l)
if [ "${counter2}" -eq 0 ]; then
#echo "mysql process";
systemctl start keepalived;
continue;
else
#echo "continue";
continue;
fi
fi
done
内容解释
- wc 统计文件中有多少行、多少单词、多少字符
-l :有多少行
-w :有多少单词
-m :多少字符