Solved

Set Unix env. var. to current IP address

Posted on 1998-05-27
19
346 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
  • 8
  • 7
  • 2
  • +2
19 Comments
 
LVL 10

Accepted Solution

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

Expert Comment

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

Expert Comment

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

Author Comment

by:radamowi
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
To get the server IP address, do an nslookup <servername> and it will return the IP address.
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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
Comment Utility
We're running the Korn Shell.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
couldn't send an answer, 'cause it's locked ;-|
0
 
LVL 2

Expert Comment

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

762 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

10 Experts available now in Live!

Get 1:1 Help Now