Get the IP instead of computer name with "who" command

I have two HP Servers, server A and server B.
When I input

who -a | grep $$

command on server A, in the output I get the IP of the machine who is executing the current process.
But when i execute the same command

who -a | grep $$

on server B, I get the computer same instead of IP.

Can some one help me in knowing what changes I need to do to get the IP on server B as well.

Thanks

Suppose if this is the output of your

who -a | grep $$ 

:

root     + pts/2        2011-11-23 03:38   .         16097 (my.hostname.xyz)

Then, you can do this work-around to get the IP address.

ping -c1 `who -a | grep $$ | awk '{print $8}' | sed 's/[()]//g'` | head -1 | awk '{print $2}'

Explanation:

who -a | grep $$ | awk '{print $8}' | sed 's/[()]//g'

will fetch you 'my.hostname.xyz'

ping -c1 my.hostname.xyz | head -1

will fetch you
PING 123.123.123.123 (123.123.123.123) 56(84) bytes of data

Piping this output to

awk '{print $2}'

will give you the required IP address i.e. 123.123.123.123.

I know this is quite some work around. But this would work on my system if I had the same problem. (Though, I'm not using HP-UX)

This is not working as

who -a | grep $$ | awk '{print $8}'

does not give me complete host-name name.
It give me first 17 letters whereas my host-name is greater than that.
Since complete host-name is not found ping cannot find the host

@bhi, that was just a sample I gave you. You have to manipulate it to suit your requirement. Try to tweak around with sed, awk or cut to get the required output.

May be someone can help if you can print the exact output when you give

who -a | grep $$

---------- Post updated at 01:39 PM ---------- Previous update was at 01:37 PM ----------

The idea here is to separate the hostname from the output that you get when you say "who -a | grep $$". Once you get the hostname, using that in ping command would display the IP address. Tweak around with ping's output to echo just the IP address.

If you have "host" (dns utility), then use that to resolve hostname to IP address.
Provide an output of who -a

--ahamaed