"who am i" in AIX

I have built a custom utility in shell script to deploy some files across AIX 6 servers.. I am using the "who am i" command to find out the IP address of the user who is using the utility to deploy the files for audit purpose.

This command returns the output with the user IP address on one server as:

user1 pts/5       Sep 30 12:47     (XX.YYY.ZZ.AAA)

but the other server does not return the IP address

user2 pts/16

I have looked around --unsuccessfully-- on this forum before putting this as a new post.. any pointers will be appreciated.

I've seen this happen before, but never discovered why. If you just need the IP Address that current user running the script connected from and they connected via ssh, you can get it from the SSH_CONNECTION environment variable. The following will return the IP Address.

echo ${SSH_CONNECTION%% *}
2 Likes

yeah that works.. thanks! but still i am curious why the behavior of who am i is different..

You're welcome.

I'm curious as well, but at the time that it occurred, I didn't cycles to figure it out, opting for a workaround instead. I've only seen it happen on the one AIX box and haven't seen it occur since.

The difference is the login session: in one case it originated from a terminal ("pts/<n>" is a terminal), in the other case it is from a network line. Only the latter carries an IP address because only here the login process (this is what ultimately feeds "who am i"s output) is aware that there is a network connection involved.

In the other case there might be a network connection involved too, but only to acquire a (virtual) terminal and then use this to log in.

If you need the IP address you are coming from inspect the established network connections, because regardless of the method there must be an established TCP connection behind every session.

# netstat -an | grep ESTABLISHED

I hope this helps.

bakunin

/PS:

This will not work if you use some "man-in-the-middle" to connect: some "putty" over Citrix or similarly working products will show you the IP of the Citrix server, not your own.

3 Likes

was following this post everyday in hopes of an explanation :slight_smile: thanks!