pipe'ing grep output to awk

This script is supposed to find out if tomcat is running or not.

#!/bin/sh
if netstat -a | grep `grep ${1}:  /tomcat/bases | awk -F: '{print $3}'` > /dev/null
then
        echo Tomcat for $1 running
else
        echo Tomcat for $1 NOT running
fi

the /tomcat/bases is a file that contains a list of all the tomcat instances running and which port number it is running

user1:yes:8080
user2:no:8081
user3:yes:8082

I know it uses netstat to check if any of the port numbers in the "bases" file is listening but i dont quite understand how this is achieved by that command shown above.

Thanks

I believe the test here simply says that the port number is listed by netstat(1) or not, so the port could be in various states, not just listening.
There is a slight flaw in that if a process was using port 80801 for instance (can they go that high?) then a test for user1 would give a false positive result. Making the first grep a "grep -w" would avoid this.
A "netstat -an" would be quicker because it would not translate any IP addresses to hostnames.

Try:

#!/bin/sh
if netstat -an | grep -q  "8080 .*LISTEN"
then
        echo Tomcat for $1 running
else
        echo Tomcat for $1 NOT running
fi