每5秒監控5000埠的shell指令碼

abin1703發表於2016-09-14
#!/bin/bash
while true;do
echo "************************************************************"
date
# ================================================================


TCPListeningnum=`netstat -an | grep ":5000" | awk '$1 == "tcp" && $NF == "LISTEN" {print $0}' | wc -l`
if [ $TCPListeningnum -eq 0 ]
then
{
echo "listener port is down">>/root/1.log
#如果5000埠down了,重啟tomcat服務
cd /Smaritbi/apache-tomcat-7.0.34/bin/
./shutdown.sh
./start.sh
}
else
{
echo "5000埠正常" >>/root/l.log
date
}
fi
sleep 5;
done
~        

執行該指令碼
nohup sh 1.sh > /dev/null 2>&1&

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30345407/viewspace-2124973/,如需轉載,請註明出處,否則將追究法律責任。

相關文章