Solved

Port Monitoring using Shell Script

Posted on 2008-10-02
14
891 Views
Last Modified: 2013-12-27
Hello Gurus,

Can someone tell me how to do Port Monitoring using Shell Script? I am planning to write a code to monitor an instance running using Port Monitorig. How to do that and find out the state?

Thanks in Advance.

Regards.
Hari.
0
Comment
Question by:rharivenkatesh
  • 4
  • 3
  • 2
  • +2
14 Comments
 
LVL 6

Expert Comment

by:peter991
ID: 22623135
snoop could do the trick.
"man snoop"
0
 
LVL 6

Expert Comment

by:peter991
ID: 22623153
$>netstat -an
will give you the state and more.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22623164
what type of ports? each port means one type of protocol. There are tools for some protocols that can be used to monitor.
0
 
LVL 5

Accepted Solution

by:
awa2008 earned 334 total points
ID: 22623244
hello

you can use a tools : lsof


lsof -i  list communications open by each process.

it shows status of state network connection processus

ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/lsof_1106-4.80-sol10-sparc-local.gz

Regards

0
 
LVL 5

Assisted Solution

by:awa2008
awa2008 earned 334 total points
ID: 22623263
This is a sample of lsof output:

[3:37pm wally]# lsof -i | egrep 'COMMAND|LISTEN|Idle'
COMMAND     PID    USER   FD   TYPE     DEVICE SIZE/OFF NODE NAME
rpcbind     104    root    3u  inet 0xf5e9eec0      0t0  UDP *:sunrpc (Idle)
rpcbind     104    root    5u  inet 0xf5970138      0t0  UDP *:32771 (Idle)
rpcbind     104    root    6u  inet 0xf5970038      0t0  TCP *:sunrpc (LISTEN)
inetd       123    root    4u  inet 0xf59702b8      0t0  TCP *:ftp (LISTEN)
inetd       123    root    5u  inet 0xf59701b8      0t0  TCP *:shell (LISTEN)
inetd       123    root    6u  inet 0xf5970538      0t0  TCP *:dtspc (LISTEN)
inetd       123    root    7u  inet 0xf5e9e640      0t0  TCP *:ident (LISTEN)
syslogd     128    root    4u  inet 0xf5e9e7c0      0t0  UDP *:syslog (Idle)
dtlogin     203    root    6u  inet 0xf601dc48      0t0  UDP *:177 (Idle)
dtlogin     203    root    7u  inet 0xf601da48      0t0  TCP *:32771 (LISTEN)
sshd        270    root    3u  inet 0xf601d648      0t0  TCP *:22 (LISTEN)
Xsun       2357 reggers    7u  inet 0xf601da48      0t0  TCP *:32771 (LISTEN)
Xsun       2357 reggers    9u  inet 0xf62027d0      0t0  TCP *:6000 (LISTEN)
dtlogin    2358    root    7u  inet 0xf601da48      0t0  TCP *:32771 (LISTEN)
   ...etc.
0
 
LVL 22

Expert Comment

by:blu
ID: 22623303
You have a few answers here, but the real problem is that you haven't really told us what you need here. What kind of ports do you mean, and what kind of monitoring?  You want to stay away from lsof on Solaris if possible. It uses a lot of resources to get its info and it uses private interfaces in the kernel and so can stop working with the application of a patch.  Netstat might do what you want or even kstats. It depends on the answer to the first question.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:rharivenkatesh
ID: 22623865
Basically we have applications running instances. These applications run in the application port something lie 27810. We do monitor the application process in Unix but we would also like to monitor the port if there is any activity. By checking the process running we cannot find out if it is hanging.

All are TCP application ports that are used to run our application instances in Websphere 6.0

Regards.
Hari.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22623928
if it is not a standard application (e.g. http) then you need to write your own tool that will interact with the application over that port and send / receive some data.

you can do this with telnet and expect if the protocol / application exchange simple text
0
 
LVL 22

Expert Comment

by:blu
ID: 22624974
If the problem you are trying to diagnose is a hang, then you need to make sure that there is a "null" function in your application, and then periodically call this "null" function to verify proper functioning of the application.
0
 
LVL 6

Assisted Solution

by:peter991
peter991 earned 166 total points
ID: 22631601
You can start out with this to see if you got any activity on the port:

snoop -d your_interface -x0 port 27810

0
 

Author Comment

by:rharivenkatesh
ID: 22631753
Hello Peter,

Could you please let me know where would this "snoop" binary executable present? Is it in /usr/bin? I am not able to run in my Solaris system. When i type "snoop" it says "not found" or does it come as a separate package? Or is it something like only a Administrators can run?

Regards.
Hari.
0
 
LVL 6

Expert Comment

by:peter991
ID: 22631882

# which snoop
/usr/sbin/snoop

regards
0
 

Author Closing Comment

by:rharivenkatesh
ID: 31502339
It does not answer completely on the requirement.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now