1833162 Members
3361 Online
110051 Solutions
New Discussion

Remote Display location

 
SOLVED
Go to solution
Robert True
Frequent Advisor

Remote Display location

How can I determine the remote IP address a user logs in from with a script? Need to set the DISPLAY env var with the script to pop some status windows back to a PC running an x-windows product such as 'Reflextions', without user intervention.

8 REPLIES 8
Pete Randall
Outstanding Contributor

Re: Remote Display location

If they're running Reflections in an X-windows environment, the DISPLAY variable should be set.

Pete

Pete
James R. Ferguson
Acclaimed Contributor
Solution

Re: Remote Display location

Hi Robert:

# who am i -T|awk '{print $9}'

Regards!

...JRF...
Bill McNAMARA_1
Honored Contributor

Re: Remote Display location

Try who -R

export DISPLAY=`who am i -R | cut -f2 -d'(' | cut -f1 -d')'|cut -f1 -d':'`:0.0

Later,
Bill
It works for me (tm)
S.K. Chan
Honored Contributor

Re: Remote Display location

Example ..

# who am i -a
jim ttyp2 May 24 07:05 . 17773 121.101.162.27
# who am i -a | awk '{print $8}'
121.101.162.27

would be that IP address you're loking for..
Darrell Allen
Honored Contributor

Re: Remote Display location

Hi Robert,

Here's what I use:

set +u
if [ "$DISPLAY" ]
then
:
else
term=`tty | cut -c6-`
export DISPLAY=`who -u | grep "$term " | awk '{print $1}'`":0.0"
fi
set -u

The reason for "set +u" is explained in:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xab497b8d1de3d5118ff40090279cd0f9,00.html

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
MANOJ SRIVASTAVA
Honored Contributor

Re: Remote Display location

Hi Robert

who am i -T is an excellent one , also you may try grep on the user name using who ,

who -T | grep user name | awk '{print $9}'


Manoj Srivastava
Robert True
Frequent Advisor

Re: Remote Display location

Thanks all; who am i -a / T is what I was looking for!
Darrell Allen
Honored Contributor

Re: Remote Display location

Hi again,

"who am i -T" looks real good!

Looking back I see my reply doesn't make much sense without some explanation. I wrote it like I did to address an issue with rlogin windows from a CDE sesson.

I use this for a small number of people that use Hummingbird Exceed from their PC. They start their CDE session on one server then open rlogin windows to other servers. Then they often su to other accounts. In the rlogin sessions, "who am i -T" will show the CDE server as where they are logged in from. Setting DISPLAY to that server won't work for displaying on their PC.

To get around that, I ASSUME the user will always log in from his own PC. I add the login name as an alias in /etc/hosts for his PC. That way I can pick off the loginname and set DISPLAY to it.

Also, I check to see if DISPLAY is already set in case the user has manually set it.

"who am i -T" (or "-u") is much more simple than getting the tty and grepping who -u output. I'll definitely start using that.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)