Solved

Port Monitoring using Shell Script

Posted on 2008-10-02
14
896 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Changing Audit Policies through scripting 5 69
Write an app 10 71
Image not there 4 57
AWK:  END { statements } 2 19
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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 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.:

828 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