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.