Solved

Set Unix env. var. to current IP address

Posted on 1998-05-27
19
351 Views
Last Modified: 2010-04-15
I use Exceed to emulate XWindows under NT. When I "rlogin" to another Unix Server I lose my current Unix DISPLAY environment variable setting on the target Server. Is there some way, via Unix commands or C code to get the current IP address so I can set the DISPLAY variable dynamically in my .profile?
0
Comment
Question by:radamowi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 2
  • +2
19 Comments
 
LVL 10

Accepted Solution

by:
rbr earned 80 total points
ID: 1251019
Use as display 127.0.0.1:0
This is the local loopback adress.
0
 
LVL 1

Expert Comment

by:cph
ID: 1251020
set the DISPLAY in your .login on the targeted server if possible
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1251021
It's not simple, but it can be done in .profile . Depends on which platforms you are rlogin'ed (nested rlogins will need a hard work).
Which platforms are you using?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:radamowi
ID: 1251022
I am running strictly HP Unix servers. The way I use Exceed is via its Workspace facility whereby I only Rlogin to one Server at a time (per workspace). This, I hope, resolves the nested Rlogin issue.

If you have further questions, don't hesitate to ask.

BTW, the first proposed solution DOES NOT WORK!
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1251023
> BTW, the first proposed solution DOES NOT WORK!

Of course, setting DISPLAY to localhost (127.0.0.1) implies that you're using the server's display itself.
DISPLAY must be set to hostname or IP of the host which displays
(someone realy gave this variable a meaningful name;-)
0
 

Author Comment

by:radamowi
ID: 1251024
So, given all of the above, the question remains ... How, in a HP UX environment, do I get the hostname or IP of the host which displays in order to set the DISPLAY environment variable? I know the IP is hanging around there somewhere because when I fire-up Exceed (version 6) and select a given Server (e.g. S01) I don't have to set the DISPLAY because it gets set automatically. My problem is when I do my first (and only) Rlogin to another Server (e.g. S02). It's the DISPLAY on the S02 Server that I would like to set. I am ready and willing to write C++ code to fetch the IP, but I don't know where to get it from. HELP!
0
 
LVL 1

Expert Comment

by:cph
ID: 1251025
To get the server IP address, do an nslookup <servername> and it will return the IP address.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1251026
Tell me which shell you're using when rlogin'ed. I'll then give you a script sniiped to be placed in the appropriate startup file.
0
 

Author Comment

by:radamowi
ID: 1251027
We're running the Korn Shell.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1251028
put following in $HOME/.profile, if it doesn't work please post the output of  who am i -R  on you HP

DISPLAY="`who am i -R|sed -e 's/[^(]*(\([^)]*\))/\1/'`:0"

radamowi, would have posted it as an answer, but ...
0
 

Author Comment

by:radamowi
ID: 1251029
The output of who am i -R:

radamowi   pts/4        Jun  2 09:10   (mtls01.mtl.imptob.com)

Your solution works fine on the initial Server I originally Logged into (i.e. mtls01) thru Exceed. However, the same command (in my .profile on mtls03) produced the above output when I then Rlogged into to mtls03!

BTW, I actually used:
export DISPLAY=`who -umR | awk '{print $8}'`
which I picked up from
http://us-support.external.hp.com/atq/bin/doc.pl/sid=249ca5ff1d60d708bf/screen=atqDocTextSrch/?PRONTOID=122452 
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1251030
> produced the above output ...
are you missing to post the output?
When you logged in to mtls03 the posted one couldn't be.

So does my solution work or does it not?

BTW, you should use:
export DISPLAY="`who -umR|awk '{print $8}`:0"

The difference to my suggestion is that this would work on HP-UX only, while mine works on most other UNIXs too :-)
0
 

Author Comment

by:radamowi
ID: 1251031
Your solution works on mtls01. It does not work on mtls03.
When I choose the mtls01 Server from my Exceed menu,
on mtls01, the output of who am i -R is:

 radamowi   pts/4        Jun  2 09:10   (198.168.207.90:0)

Then, when I Rlogin to mtls03, the output of who am i -R is:

 radamowi   pts/4        Jun  2 09:10   (mtls01.mtl.imptob.com)

I am looking for a way to get the correct (client) IP address AFTER an Rlogin to mtls03.
 
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1251032
Hmm this is a nested rlogin, it goes like this:

    win (Exceed) -> mtls01 (X) -> mtls03 (rlogin from mtls01)

As I said, it's not easy but can be done. Could you give some more informations please:

    1.   are there more than one rlogin at a time from
      a) the same user (same and/or different workstation)
      b) different users
    2.   is there a "clean" logout, or may some rlogin connections hang around
    3.   which HP-UX (uname -a)
0
 

Author Comment

by:radamowi
ID: 1251033
Answers:
1) I am running strictly HP Unix servers. The way I use Exceed is via its Workspace facility whereby I only Rlogin to one Server at a time (per workspace). I will have only one Rlogin per workspace (e.g. one workspace for Rlogin from mtls01 to mtls03 and another workspace for Rlogin from mtls01 to mtls05).
2) Yes, there is a "clean" logout.
3) HP-UX mtls03 B.10.20 A 9000/881
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1251034
an other question (have no HP-UX 10.20 handy):

   is the remote shell still  remsh  or it  rsh  now

Posting an answer soon, would you please reject the current one.
0
 

Author Comment

by:radamowi
ID: 1251035
To: ahoffman
I'm still waiting for the answer you said you would send soon. Is there something else that you need to know?

Since I have one server (mtls30) that has NFS mount points defined to (all) the other servers I need to access (mtls01, mtls03 and mtls05) I thought I would pipe the IP address to three separate files on each of the other servers and pipe the file's contents into my .profile DISPLAY variable on mtls01, mtls03 and mtls05 respectively.

I would prefer a more dynamic solution because the above technique forces me to use mtls30 as my primary login entry point.

Is there a system memory block that I can access via a C++ program that will return the current IP address. This way I could copy the program to all my Servers and call it from each  .profile regardless of which Server I initially logged into?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1251036
couldn't send an answer, 'cause it's locked ;-|
0
 
LVL 2

Expert Comment

by:seedy
ID: 1251037
radamowi,

Here is another approach.  It may have pitfalls, and it is based on the assumptions:
- that you do not use tset command in .profile.
- you will never work with any terminal whose name contains '%'

If you use tset, please comment it out to make this solution work.  If you absolutely need 'tset', then forget this solution.

Approach:  
man rlogin states "current TERM environment variable is propagated across the network and used to set the initial value of your TERM environment variable on the remote host."  So, lets piggy back the content of DISPLAY variable onto TERM.

1.  Re-define your rlogin command to do something more.
    Add the following line to your .kshrc file (create one if needed)
        alias -x rlogin="TERM=\${TERM}%\${DISPLAY} rlogin"

2.  Add the following to your .profile
       
        #Get DISPLAY variable if it is piggy backed on to TERM
                if [ `expr index "$TERM" '\%'` -gt 0 ] ; then
                        DISPLAY=`echo $TERM | sed 's#^.*%##'`
                        TERM=`echo $TERM | sed 's#%.*$##'`
                fi
        #END

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

696 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