前段时间公司服务器的tomcat总是出问题,所以写了一个监听8080端口的小脚本。拿出来和大家share一下,不足之处还请指正。
#! /bin/bash
##### define TOMCAT,DATE #####
TOMCAT=$(netstat -an |grep "0.0.0.0:8080" |gawk '{print $4}')
DATE=$(date)
##### confirm tomcat server is running or stoped and run the script below #####
if [ "$TOMCAT" = "0.0.0.0:8080" ]; then
echo [" "$DATE" "]: tomcat is running now! >> /root/tomcat_confirm.log
else
/sbin/service tomcat restart
echo [" "$DATE" "]: tomcat is stoped and restart now! >> /root/tomcat_confirm.log
fi