Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2002-04-23
12
Medium Priority
?
291 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
ID: 6964374
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 200 total points
ID: 6964397
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
ID: 6964939
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:elfie
ID: 6964963
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
ID: 6965035
oops, forgot to mention nested logins (nearly impossible to handle), thanks elfie
0
 
LVL 38

Expert Comment

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

and remember REMOTEHOST available in tcsh
0
 
LVL 51

Expert Comment

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

Expert Comment

by:yuzh
ID: 6970210
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
ID: 6970541
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
ID: 6976158
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
ID: 6976488
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
ID: 6977755
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

824 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