robmandu

Determine which process is listening at a specific TCP port on AIX

Software developers are ignorant, lazy, and sometimes evil.

What I mean is, they often giving astoundingly detailed - yet useless - error messages when conditions for their code to run aren’t right. Like this gem from an IBM WebSphere log:

Caused by: java.sql.SQLException: Unable to connect: The application could not log on to the server “myserver.domain.com:123456”. The user ID “XXXX” or the password is incorrect. DSRA0010E: SQL State = null, Error Code = 0

Now, apparently, some webapp is trying to connect to a SQL db. Which webapp? Which db? Why not show the actual userid (those XXXX’s were original to the log)?

So, I’ve got to go on a little scavenger hunt. 

I have two pieces of information with which to work:

  1. the server’s hostname
  2. the port number used for authentication to the SQL db

Let’s get started.

First of all, I need to get information about that TCP port:

# netstat -Aan | grep 123456

f100050003308bb8 tcp        0      0  *.123456            *.*                LISTEN

Note the little “a” option after the big “A” for netstat. That’s important because it gets the socket identifier we need for the next step:

# rmsock f100050003308bb8 tcpcb

The socket 0xf100050003308808 is being held by proccess 987654 (foobar).

Well hey, something we can work with finally. An actual process id… and even the name of the executable. Now, let’s run this thing all the way to ground:
# ps -eaf | grep 987654

     UID      PID     PPID   C    STIME    TTY  TIME CMD

   rogue  987654  11335577   0   Nov 03      -  0:14 /some/rdbms/start.sh -option1 -option2 -etc

Alright, now I know where to go and what to solve. 
And because I’m somewhat familiar with the solution at play, I can tell you that the developer has to allow for a variety of potential RDBMS solutions (in-house proprietary, MySQL, PostgreSQL, whatever)… but still, I also know that the developer’s code is informed as to which one of those it is. He has information that he’s not sharing. Relevant, useful information that would save me time. 

Notes

  1. robmandu posted this

About

NOTICE.
--
Persons attempting to find a motive in this narrative will be prosecuted; persons attempting to find a moral in it will be banished; persons attempting to find a plot in it will be shot.
--
BY ORDER OF THE AUTHOR
Per G. G., CHIEF OF ORDNANCE

Credits