On 03.01.24 10:18, Olaf Kock wrote:
Here's an option:
On 03.01.24 09:41, Chaudhary, Mohit wrote:
Hi,
Please find below script code which has been written.
STAT=`netstat -luptn | grep 8080 | awk '{print $6}'`
if [[ "$STAT" != "LISTEN" ]];
then
echo "Tomcat instance down" >> $MESSAGE
mail -s "Tomcat Instance Down on $HOSTNAME" $mailto < $MESSAGE
Thanks & Regards,
Mohit Chaudhary
netstat -luptn contains the "p" option (which lists the PID/Program
name). It also contains -u, which includes UDP ports. Both most likely
not helpful in your case, and a sign that this script was quickly
gobbled together and not well designed.
grep 8080 does not just match for a port, but will also trigger for
any listed PID (or other output) containing those 4 characters. As
you'll also see numeric IPV6 addresses (local or foreign ones) - and
even local IPV6 addresses can change over time - there's another
possibility for unintended matches.
So, assuming that there is some other output from netstat that
somewhere contains "8080", but not "LISTEN" (or maybe if the output is
multi-line), you'll get a false positive hit.
To validate that you're running into such an issue, you can add the
grepped netstat output to the mail (before applying awk) - so either
cache that output, or simply execute it again, piping it to $MESSAGE.
One more nail in the coffin:
Validate by just executing "netstat -luptn | grep 8" on the command line
(to simulate multiple hits), and look at the output that you (would) get
from awk: The -u option doesn't even result in netstat to print LISTEN
in column 6, so awk prints the PID column. And indeed, if multiple lines
match your grep, you're comparing (e.g.) "LISTEN LISTEN 34523/java" to
"LISTEN", which obviously does not match.
Which means: Your script is definitely wrong. Tomcat is not to blame.
Best,
Olaf
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org