• C

Set Unix env. var. to current IP address

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?
Who is Participating?
Use as display
This is the local loopback adress.
set the DISPLAY in your .login on the targeted server if possible
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?
WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

radamowiAuthor Commented:
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!
> BTW, the first proposed solution DOES NOT WORK!

Of course, setting DISPLAY to localhost ( 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;-)
radamowiAuthor Commented:
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!
To get the server IP address, do an nslookup <servername> and it will return the IP address.
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.
radamowiAuthor Commented:
We're running the Korn Shell.
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 ...
radamowiAuthor Commented:
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
> 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 :-)
radamowiAuthor Commented:
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   (

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.
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)
radamowiAuthor Commented:
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
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.
radamowiAuthor Commented:
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?
couldn't send an answer, 'cause it's locked ;-|

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.

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#%.*$##'`

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.