Sponsored Content
Top Forums Shell Programming and Scripting Get opened port with given PID? Post 302540501 by linuxadmin on Thursday 21st of July 2011 12:58:45 AM
Old 07-21-2011
Quote:
Originally Posted by shamrock
You should be able to grep the port tomcat is listening on from the output of lsof
Dear shamrock, i tried as you told
Code:
[root@linux ~]# lsof | grep 8080
automount  2867      root  mem       REG       8,11      98080    1006186 /usr/lib/autofs/lookup_file.so

And zaxxon, what you told is correct only. I can get it from server.xml file.
But my problem is : we have to use this script in a number of servers. And the server.xml file may be manually edited. There will be http & https connections also. The part <Connector port="portNum" will edit manually. And there is a chance to change the alignment also.
Code:
[root@linux ~]# grep 8080 /tomcat6/apache-tomcat-6.0.18/conf/server.xml
         Define a non-SSL HTTP/1.1 Connector on port 8080
    <Connector port="8080" protocol="HTTP/1.1" 
               port="8080" protocol="HTTP/1.1"

So upto my knowledge , there is only one way , that to GET the PORT number from PROCESS id.
Code:
[root@linux ~]# ps -ef | grep tomcat
root      7976     1  0 Jul18 ?        00:22:11 /usr/java/jdk1.6.0_13/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/tomcat6/apache-tomcat-6.0.18/conf/logging.properties -verbose:gc -XX:+PrintGCDetails -XX:MaxPermSize=512M -Xms1024M -Xmx1024M -Djava.awt.headless=true -XX:+UseParallelOldGC -XX:+UseParallelGC -Djava.endorsed.dirs=/tomcat6/apache-tomcat-6.0.18/endorsed -classpath :/tomcat6/apache-tomcat-6.0.18/bin/bootstrap.jar -Dcatalina.base=/tomcat6/apache-tomcat-6.0.18 -Dcatalina.home=/tomcat6/apache-tomcat-6.0.18 -Djava.io.tmpdir=/tomcat6/apache-tomcat-6.0.18/temp org.apache.catalina.startup.Bootstrap start
root     28214 28183  0 10:02 pts/1    00:00:00 grep tomcat

[root@linux ~]# ps -ef | grep catalina | grep -v "grep catalina" |  grep -v "catalina.out"|awk '{print $2}' | head -1
7976

[root@linux ~]# fuser 8080/tcp
8080/tcp:             7976       -->> I need vice-versa of this. That is , by giving process id , i should get port number. I tried by grep of fuser but i couldn't find.

 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Session PID & socket connection pid

1. If I use an software application(which connects to the database in the server) in my local pc, how many PID should be registered? Would there be PID for the session and another PID for socket connection? 2. I noticed (through netstat) that when I logged in using the my software application,... (1 Reply)
Discussion started by: pcx26
1 Replies

2. HP-UX

To find pid from port number

Hi, I am working on HP-UX Release 11i. I want to find the process id (PID) of the process running on a particular port. lsof command fuser does not work on this system. Please suggest some alternative. Thanks (6 Replies)
Discussion started by: gmat
6 Replies

3. UNIX for Dummies Questions & Answers

pid from port number in AIX

Hello guys, How to shut down a port number in AIX. May be first I need to find out what is the process ID of that process that listens to this particular port.. Is there any command to find a process ID from the port number other than "lsof". thanks (1 Reply)
Discussion started by: solaix14
1 Replies

4. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

5. UNIX for Dummies Questions & Answers

Find PID for a port

Hi, I need to find the PID for a given port on the below system. HP-UX mymachine B.11.31 U ia64 3223107173 unlimited-user license How can I ? (4 Replies)
Discussion started by: mohtashims
4 Replies

6. HP-UX

Find port for Pid

Hi, Is this the most appropriate way of finding the listen port number given the pid is "16659" ? lsof -Pan -i tcp -i udp | grep 16659 | grep -i "listen"If so, how can I extract "7001" and assign it to a variable say myport=7001 from the below output which happens to be actual port number? ... (1 Reply)
Discussion started by: mohtashims
1 Replies

7. UNIX for Advanced & Expert Users

Find PID using a Port?

Hi, I do not have root user credentials nor do I have the functional id of the process that uses port 80. How can I find the pid of the process using the port number 80 ? Operating System: Linux (6 Replies)
Discussion started by: mohtashims
6 Replies

8. Solaris

How to find port number wwn of particular port on dual port HBA,?

please find the below o/p for your reference bash-3.00# fcinfo hba-port HBA Port WWN: 21000024ff295a34 OS Device Name: /dev/cfg/c2 Manufacturer: QLogic Corp. Model: 375-3356-02 Firmware Version: 05.03.02 FCode/BIOS Version: BIOS: 2.02; fcode: 2.01;... (3 Replies)
Discussion started by: sb200
3 Replies
ipa-client-automount(1) 					 IPA Manual Pages					   ipa-client-automount(1)

NAME
ipa-client-automount - Configure automount and NFS for IPA SYNOPSIS
ipa-client-automount [OPTION]... <location> DESCRIPTION
Configures automount for IPA. The automount configuration consists of three files: o /etc/nsswitch.conf o /etc/sysconfig/autofs o /etc/autofs_ldap_auth.conf By default this will use DNS discovery to attempt to determine the IPA server(s) to use. If IPA servers are discovered then the automount client will be configured to use DNS discovery. If DNS discovery fails or a specific server is desired, use the --server option. The default automount location is named default. To specify a different one use the --location option. The IPA client must already be configured in order to configure automount. The IPA client is configured as part of a server installation. There are two ways to configure automount. The default is to use sssd to manage the automount maps. Alternatively autofs can configured to bind to LDAP over GSSAPI and authenticate using the machine's host principal. The nsswitch automount service is configured to use either sss or ldap and files depending on whether SSSD is configured or not. NFSv4 is also configured. The rpc.gssd and rpc.idmapd are started on clients to support Kerberos-secured mounts. OPTIONS
--server=SERVER Set the IPA server to connect to --location=LOCATION Automount location -S, --no-sssd Do not configure the client to use SSSD for automount -d, --debug Print debugging information to stdout -U, --unattended Unattended installation. The user will not be prompted --uninstall Restore the automount configuration files FILES
Files that will be always be configured: /etc/nsswitch.conf Files that will be configured when SSSD is the automount client (default): /etc/sssd/sssd.conf Files that will be configured when using the ldap automount client: /etc/sysconfig/autofs /etc/autofs_ldap_auth.conf EXIT STATUS
0 if the installation was successful 1 if an error occurred IPA
May 25 2012 ipa-client-automount(1)
All times are GMT -4. The time now is 05:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy