getting an exporting an ipaddress - is awk the man for the job?

to run an xwindows session from our box i type this:
DISPLAY=999.99.99.99;export DISPLAY.

then i noticed using who -T that the system already knows
the ip i am logged into and wrote this to capture it:
who -T | awk '/myname/ {print $9}'

i got to wondering how i can capture this automatically so that when i needed the gui i could just type an alias and sit back and relax.

can i just capture it automatically at login and store it during the session? if that was undesirable, is there a smarter way to extract it than using my clumsy awk?

thanks for your insight.
banbaAsked:
Who is Participating?
 
yuzhConnect With a Mentor Commented:
if you want to detect your IP for setting DISPLAY, who is not a porper command to do it.

   #who | grep myusername | awk '{print $6}'

   will give the IPs, what happen if you login from more than one machine? you'll not be able to get the correct for setting the display.

   Check if your have tcsh installed on your system, type in:
   #which tcsh

   if you have tcsh installed then your can use the following tcsh script to do the job:

#!/bin/tcsh -f

#
#
      if ( $?REMOTEHOST ) then
#          setenv MACHINE `echo ${REMOTEHOST} | cut -d. -f1`
           setenv MACHINE `echo ${REMOTEHOST}`
           echo "${MACHINE}:0.0" > ~/.dsplay
      else
           setenv MACHINE `hostname`
           echo "${MACHINE}:0.0" > ~/.dsplay
      endif

#=======================================================

put it somewhere, eg yourhome/bin nameed it ckremote

add the followings .profile

#
# Auto set the DISPLAY for X server
#
    ~/bin/ckremote
    DISPLAY=`cat ~/.dsplay`
    export DISPLAY



Cheers!
============
yuzh
0
 
jlevieCommented:
You could capture the IP and export the DISPLAY var at login by including the shell commands in your shell's init script.

If your system supports it, you could use ssh to connect and it'll automatically forward X to your local system.
0
 
ahoffmannCommented:
hmm, sounds simple, but is complicated in real life.
Is it always the same UNIX you're connecting to? then a simple awk might do it. Please tell us which UNIX you come from, and which one is remote.

If you have various flaviours of local and remote UNIXs, then check following:

     echo $REMOTEHOST
     who am i
     who am i -R
     whoami
     tty
     w
     netstat -an|egrep ':22|:23|:513'

probably you need to combine information from several commands.
There're lot of dragons to beat ...
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
elfieCommented:
knowing the environment is important.

When using lots of 'rlogin' life is complicated.
When dialing in onto a NT/WIn2000 box and then  connecting  via WRQ, Exceed, ... to unix things get really complicated. In this case the DISPLAY will end on ":0" any more, but some other numbers. In this case you need then just the ip address.

What i used to do, is provide user with some menu (dynamically build using method explained in above 'comments', and have the user choose. The latest choosen option can be the 'default' value.
0
 
ahoffmannCommented:
oops, forgot to mention nested logins (nearly impossible to handle), thanks elfie
0
 
yuzhCommented:
I agree with ahoffmann, nested logins (nearly impossible to handle),.

and remember REMOTEHOST available in tcsh
0
 
ahoffmannCommented:
yuzh@idg, $REMOTEHOST is IRIX only, not tcsh
0
 
yuzhCommented:
Try to use tcsh (for Solaris or HP_UX), $REMOTEHOST is there.

I am using it for both Solaris and HP_UX for my users.
0
 
ahoffmannCommented:
nice info, yuzh, hich version of tcsh do you use?
Are you shure that REMOTEHOST is not set by any of the shell's start up scripts (/etc/csh.{login,cshrc}, etc.)

banba, sorry for being off-topic
0
 
yuzhCommented:
Hi ahoffmann,

   I have a few different version of tcsh installed on my network.

   eg.

   for Solaris (Sparc), use an old version:
   version tcsh 6.08.00 (Astron) 1998-10-02 (sparc-sun-solaris)

   For Solaris (intel), tcsh 6.10.xx
   For HP-UX (10.20) use tcsh 6.10.xx.

   For Linux, use
   version tcsh 6.11.00 (Astron) 2001-09-02 (i386-intel-linux)

   Nothing set by the startup script. I wrote all the setup script for my users.

   They all works.

   Just try it out yourself.

   
   
 
0
 
ahoffmannCommented:
hmm, my
tcsh 6.08.05 (Astron) 1999-05-11 (i386-intel-linux)
doesnt use REMOTEHOST, even strings does not give REMOTEHOST in tcsh executable, so I believe it doesn't know it. Strange ...
Probably HP-UX sets the variable for login|rlogin.
0
 
banbaAuthor Commented:
thanks, that worked great. also thanks to you other folks, i value the discussion as it teaches me HOW to approach some problems.

0
All Courses

From novice to tech pro — start learning today.