Solved

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

Posted on 2002-04-23
12
249 Views
Last Modified: 2013-12-06
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.
0
Comment
Question by:banba
12 Comments
 
LVL 40

Expert Comment

by:jlevie
Comment Utility
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
 
LVL 38

Accepted Solution

by:
yuzh earned 50 total points
Comment Utility
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
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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
 
LVL 3

Expert Comment

by:elfie
Comment Utility
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
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
oops, forgot to mention nested logins (nearly impossible to handle), thanks elfie
0
 
LVL 38

Expert Comment

by:yuzh
Comment Utility
I agree with ahoffmann, nested logins (nearly impossible to handle),.

and remember REMOTEHOST available in tcsh
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
yuzh@idg, $REMOTEHOST is IRIX only, not tcsh
0
 
LVL 38

Expert Comment

by:yuzh
Comment Utility
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
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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
 
LVL 38

Expert Comment

by:yuzh
Comment Utility
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
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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
 

Author Comment

by:banba
Comment Utility
thanks, that worked great. also thanks to you other folks, i value the discussion as it teaches me HOW to approach some problems.

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now