Solved

Port Monitoring using Shell Script

Posted on 2008-10-02
14
895 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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
 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

803 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