Solved

Check whether port is used

Posted on 2006-07-24
3
381 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
  • 3
3 Comments
 
LVL 16

Accepted Solution

by:
Hanno Schröder earned 50 total points
ID: 17167907
a short
  netstat -an | grep 8001
should show you
0
 
LVL 16

Expert Comment

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

Expert Comment

by:Hanno Schröder
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now