shell监控端口

vim /root/jiankong.sh
#!/bin/bash
DATE=`date '+%Y%m%d-%H%M%S'`

TCPListeningnum=`netstat -an | grep ":8080" | awk '$1 == "tcp" && $NF == "LISTEN" {print $0}' | wc -l`
if [ $TCPListeningnum -eq 0 ]
then
{
        echo $DATE"---------------listener port is down" >> /root/jk.log
#如果8080端口down了,重启java服务
cd /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/ext/
java -jar -Djava.ext.dirs="/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/ext/" /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/ext/JavaBridge.jar SERVLET_LOCAL:8080 3 JavaBridge.log &
}
else
{
#       echo $DATE"---------------8080端口正常" >> /root/jk.log
        sleep 1;
}
fi

#每1分钟,监控java桥接器,端口挂了,自动重启

*/1 * * * * /root/jiankong.sh >> /root/jk.log 2>&

你可能感兴趣的:(linux,linux,运维)