Solved

Check whether port is used

Posted on 2006-07-24
3
388 Views
Last Modified: 2013-12-27
We are using a report server that listens on port 8001. If we start the report server (through a script) a second time, it will fail because port 8001 is already taken up by the first instance. How can I modify my script to check that the port is already taken up, so that I won't start the server again?

I can use telnet, but it's going to prompt me to enter something. All I need is to check that the server is listening on that port.
0
Comment
Question by:yongsing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 16

Accepted Solution

by:
Hanno P.S. earned 50 total points
ID: 17167907
a short
  netstat -an | grep 8001
should show you
0
 
LVL 16

Expert Comment

by:Hanno P.S.
ID: 17167922
Status like idle, listen, established shwo that somthing bound to it already.
0
 
LVL 16

Expert Comment

by:Hanno P.S.
ID: 17168077
If you are looking for a certain port for a given process ID (pid) use
# pfiles $pid | grep "sockname:" | grep "port:" | awk '{print $NF}'`

If you need a report for ALL ports, run this script:
#!/bin/ksh
for pid in `ps -ef -o pid | tail +2` ; do
 port=`pfiles $pid 2>&1 | grep "sockname:" | grep "port:" | awk '{print $NF}'` > /dev/null
 [ ! -z "$port" ] &&  echo "`pfiles $pid 2>&1 | grep \"^$pid:\"` => `echo $port`"
done

JustUNIX
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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.:

623 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