Today I needed to find out the IP address of the currently logged on user (e.g. via SSH) on a Linux system to use it in a bash script. After searching the web for a simple tool for this task for quite some time, I finally came up with the following bash script to get me the needed information. Is there any way to obtain the IP address in a simpler way by using built in Linux tools?
HOST=`who am i | sed -r "s/.*\((.*)\).*/\\1/"`
IP=`host $HOST | sed -r "s/.* has address (.*)/\\1/"`