• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 904
  • Last Modified:

Port Monitoring using Shell Script

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
rharivenkatesh
Asked:
rharivenkatesh
  • 4
  • 3
  • 2
  • +2
3 Solutions
 
peter991Commented:
snoop could do the trick.
"man snoop"
0
 
peter991Commented:
$>netstat -an
will give you the state and more.
0
 
omarfaridCommented:
what type of ports? each port means one type of protocol. There are tools for some protocols that can be used to monitor.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
awa2008Commented:
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
 
awa2008Commented:
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
 
Brian UtterbackPrinciple Software EngineerCommented:
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
 
rharivenkateshAuthor Commented:
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
 
omarfaridCommented:
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
 
Brian UtterbackPrinciple Software EngineerCommented:
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
 
peter991Commented:
You can start out with this to see if you got any activity on the port:

snoop -d your_interface -x0 port 27810

0
 
rharivenkateshAuthor Commented:
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
 
peter991Commented:

# which snoop
/usr/sbin/snoop

regards
0
 
rharivenkateshAuthor Commented:
It does not answer completely on the requirement.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now