Script to Monitor List of Ports


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to Monitor List of Ports
# 1  
Old 10-21-2010
Script to Monitor List of Ports

Hi,

I'm in need of a script that can monitor a list of 12 ports.. If one of the ports isn't in listening mode then email me..

The list of ports are 26401 - 26412..
# 2  
Old 10-21-2010
netstat -an | grep -Ec . . . | read ct

Of course, to really prove they are served, you could telnet to each and see if it connects, prompts, etc., but you might alter your app connect stats at the same time -- classic Heisenberg.
# 3  
Old 10-21-2010
DGPickett,

I can't just pull the full count of them since I need to know exactly which one isn't in "listening" mode..

You can't actively telnet into the ports, although the app listens (this is because of the function of the app). But it is safe to assume that if it's not in LISTEN mode, then it's not functioning.
# 4  
Old 10-21-2010
Many tcp listeners can be made to respond using telnet. I am not talking about logging in, telnet is just a trivial, general tcp client with some optional behaviors. Telnet to a web server port 80 and type 'GET / HTTP/1.0'+CR+CR. If you telnet to most servers, and they do not respond, still you know they are really listening, even if you do not know the magic bytes to make them talk. For instance, if inetd is the real listener, and the app is missing/crashing, the connection may take for an instant and they be broken off.

Make a file of good netstat -an listen lines and comm them to see if any disappeared.
# 5  
Old 10-21-2010
Yup.. I know what you mean.. however, this application doesn't allow for any type of connections through the port, since it's an internal license adapter. It just refuses connection when trying to telnet. The application cannot be modified, but I was told that 100% reliability that LISTEN means it's working (it's what I'm told from the application, so it's all I can agree to).

Here's what I've come up with:

NETSTAT=`netstat -ant | grep LISTEN | awk '{ print $4 }'`
CCTEST="my_email@email.com another_email@email.com"

for PORT in `seq 26401 26412`; do
echo "$NETSTAT" | grep $PORT &> /dev/null
if [ $? -ne 0 ]; then
echo "Port $PORT is down on `hostname`i X.X" | mail -s "Port $PORT is down on `hostname`" $CCTEST
else
echo "Port $PORT is =)"
fi
done
# 6  
Old 10-21-2010
Maybe it expects real fast input, or a specific client port or host, or tickles telnet to reveal itself as not the app.

Yeah, that looks pretty good.
  • Time stamps in email and logs are nice, think date "+%Y-%m-%d %H:%M:%S . . ." in place of echo.
  • I keep the host left on subjects so I detect testing vs production more quickly.
  • You can tee the mail message to /dev/stderr on some UNIX like Solaris, so it also goes into the log.
  • You might want to accumulate a $BAD_LIST and send one mail for all if any.
# 7  
Old 10-21-2010
I added some time stamps.. although the version of AIX I'm on didn't like date "+%Y-%m-%d %H:%M:%S" just to re mediate the problem.. I assigned DATE to the first subset, and TIME to the second.

I've thought of doing a $BAD_LIST .. but this is a temporary thing, and they believe only 1 goes down.. I'll def do that.. if they want (I can incorporate it now, and just change the mail line to include $BAD_LIST instead of $PORT.. ).. but meetings all day..

It's on AIX 5.2, which I'm not good with (I'm a linux guy).. so was a little different for me..

Last edited by eclipseagent; 10-21-2010 at 06:51 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Script monitor website wth default tomcat script

Hi all, on our application server we have the following script that monitor the status of the website, my problem here is that i have edite the retries from 3 to 5, and the timewait to 120 second, so the script should check 5 times every 2 minutes, and if the fifth check fails it must restart... (0 Replies)
Discussion started by: charli1
0 Replies

2. Linux

Packages that monitor OS configs and service/ports?

I have several Redhat servers and workstations that I need to be able to monitor for any changes and be notified of any changes to the OS. The features I need to specifically monitor are: ports - opening of new ports that are not already in a whitelist services - any starting or attempts to start... (1 Reply)
Discussion started by: JCDinPGH
1 Replies

3. UNIX for Dummies Questions & Answers

How do i list running process with the ports they are using?

How do i list the running process and also view the ports they are listening to at the same time? (3 Replies)
Discussion started by: mena
3 Replies

4. Solaris

List of Ports being used.

Hi, I have 2 queries: a) Is it possible that a port no., not defined in /etc/services, be used by an application. b) how do i find the list of ports is being currently used on my Solaris box(if entry not made into /etc/services) I donot have "lsof" installed on my box. (3 Replies)
Discussion started by: EmbedUX
3 Replies

5. UNIX for Advanced & Expert Users

script for unassigned ports

Hi Guys, could you help me with this. I need a script where if we enter the hostname and range of port numbers, the script must be able to give me the ports that were unassigned to any of the services installed. Thanks, Charan (5 Replies)
Discussion started by: charan314
5 Replies

6. Solaris

List TCP ports with process

Hello, One of our developers is asking for a command/script in Solaris similar to "netstat -anp" in Linux. He gave this output as an example: root@xxx:~# netstat -anp | grep LISTEN tcp 0 0 0.0.0.0:7937 0.0.0.0:* LISTEN 16082/nsrexecd tcp 0 ... (7 Replies)
Discussion started by: vimes
7 Replies

7. Solaris

how to monitor ports

I run into this issue occasionally and just looking for suggestions on how others solved it. I would like to monitor ports on a large number of systems and would like to determine which systems are listening on specific ports. I know there are heavy-weight apps that provide this such as HP ovo... (6 Replies)
Discussion started by: mhm4
6 Replies

8. AIX

How to find list of userdefined ports in aix

I want to know list of userdefined ports available in aix .Suppose I want to run a process at port 20 .using netstat i could able to find out that no process is listening at that 20 .Still I am not able to bring my process up at port 20. Thanks kittu (1 Reply)
Discussion started by: kittu1979
1 Replies

9. UNIX for Dummies Questions & Answers

get the list of open ports in unix?

Hi, what is the unix command to get the list of all open ports in unix? Thank you in advance (1 Reply)
Discussion started by: zainab
1 Replies

10. UNIX for Dummies Questions & Answers

list all ports and their relative IP@ if any

Hi all i'm working on a LINUX-based platform. i'm little confused with PORTs. i have my platform connected to many other platforms, i need to know the relative port for each IP@. i know the IP of each connected platform to mine, but i'm not sure about the relative PORT for each platform...... (4 Replies)
Discussion started by: samsal_991
4 Replies
Login or Register to Ask a Question