Monitoring Tomcat Service with shell script

Hello Forum,

I have prepared script to monitor the tomcat status.
Following is the script which will monitor tomcat instance.
I need little modifcation in the script.

My script will grep for process,
the output of grep command will analyze by if condition under for loop and will send following echo message on the email.
The echo message which will get send is as follows echo "Tomcat Application Server is down on myserver" | mailx -s "tomcatserver of myserver is down" $email.
I need modifcation here ,it sends very generalised message i.e tomcat is down.
I would like it to send message which tomcat is going down whether it is tomcat Port 7007 7008 8001 8008 8009 8023 8024 kindly assist.

#!/usr/bin/ksh
 
# Lisr for Port
list='7007
7008
8001
8008
8009
8023
8024'
for li in $list
do
RESULT=`netstat -na | grep $li |grep "LISTEN" | wc -l`
 
if [ "$RESULT" = 0 ]; then
echo "TOMCAT PORT $li STILL NOT LISTENING"
else 
echo "TOMCAT PORT $li IS LISTENINS AND SO TOMCAT WORKING"
fi
done

Where is the mailing part of the script? Is it inside the above mentioned loop or somewhere else?

Can't you just include the $li variable in the email message? That will tell which one is down, right?

msg="Tomcat Application Server on port $li is down on myserver"
subject="tomcatserver port $li of myserver is down"
echo "$msg" | mailx -s "$subject" $email