Solved

Check whether port is used

Posted on 2006-07-24
3
386 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
NTP Server in VMware 5 460
unable to put logic for reading multiple repo in a single file 4 105
unix solaris snoop command 6 138
how to send mail in unix 2 47
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…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

739 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