Automatically Set DISPLAY Environment Variable after rlogin

Automatically Set DISPLAY Environment Variable after rlogin

Post by Tony Georg » Fri, 02 Apr 2004 06:37:45



Hi,

Maybe it's a brain lapse, but I seem to remember that there was a clever way
to have your X-server DISPLAY variable carried with you when you rlogin from
one machine to another.  I'm using TCSH as our default shell, so I can use
the REMOTEHOST variable for one hop.  Is there something special I can do if
I have two hops (i.e. rlogin into one machine and then into another after
that)?

Thanks!

TG

 
 
 

Automatically Set DISPLAY Environment Variable after rlogin

Post by Ed Morto » Sat, 03 Apr 2004 00:47:26



> Hi,

> Maybe it's a brain lapse, but I seem to remember that there was a clever way
> to have your X-server DISPLAY variable carried with you when you rlogin from
> one machine to another.  I'm using TCSH as our default shell, so I can use
> the REMOTEHOST variable for one hop.  Is there something special I can do if
> I have two hops (i.e. rlogin into one machine and then into another after
> that)?

> Thanks!

> TG

This is something of a hack, but in case you don't get a better answer:

rlogin carries the TERM variable with it to the new host so you can load
it up with whatever variables you want set before you rlogin, then just
eval it when you get to the new machine.

e.g. If you're going from machine A to machine B, you can do this on A:

        TERM=TERM=$TERM\;DISPLAY=$DISPLAY
        rlogin B

and then this on B:

        eval $TERM

and it'll set TERM and DISPLAY to whatever they were originally set to.

If you do the above from the command line, then you need to remember to
do an "eval $TERM" again when you get back to A so in reality it's best
to create your own rlogin command called, say, something like "myrlogin"
(or "rlogin" if you specify the path to the official rlogin within the
script) containing:

        TERM=TERM=$TERM\;DISPLAY=$DISPLAY
        rlogin "$1"

and then invoke:

        myrlogin B

so that the setting of TERM and the rlogin is in a sub-shell so that
when you return to "A" from the rlogin you don't need to do an "eval $TERM".

Regards,

        Ed.

 
 
 

Automatically Set DISPLAY Environment Variable after rlogin

Post by Michael Tos » Sat, 03 Apr 2004 03:43:45



Quote:> Hi,

> Maybe it's a brain lapse, but I seem to remember that there was a clever way
> to have your X-server DISPLAY variable carried with you when you rlogin from
> one machine to another.  I'm using TCSH as our default shell, so I can use
> the REMOTEHOST variable for one hop.  Is there something special I can do if
> I have two hops (i.e. rlogin into one machine and then into another after
> that)?

> Thanks!

> TG

The best solution is to install ssh1, it can be configured to behave
exactly as rsh/rlogin/rcp, (only that it is ssh/slogin/scp).
Unfortunately, it disables ssh2 (and ssh2 cannot fully replace
rsh/rlogin/rcp).

Some telnet implementations do automatic display handling, too.

Perhaps you can use the script rxterm (or at least an excerpt):

#!/bin/sh
# *** If you don't have /bin/ksh then try /bin/sh or bash or zsh ***
#==============================================================================
# rxterm
# ======
# Start up a remote xterm session, carrying over current $DISPLAY,  and
# executing xauth. The remote machine must be set up to trust you (via
# /etc/hosts.equiv or ~/.rhosts), as for rsh or rcp.
#
# usage:
#   rxterm [-l username] [-d display] [-r remoteXdir] hostname [xterm options]
#
# Copyright:

# are free to copy it (at your own risk) provided this notice is included. The
# author would be pleased to receive comments and bug reports, but does not
# promise to act upon them.

# $Log: rxterm,v $
# Revision 1.6  94/03/09  11:18:39  czis303
# Use -T instead of -title to define title. This allows user to override with
# either -T or -title.
#
# Revision 1.5  94/02/23  17:49:35  czis303
# Replace ksh-specific print by echo.
#
# Revision 1.4  94/02/09  16:29:29  czis303
# Use execqt when remote machine has it, for greater efficiency.
#
# Revision 1.3  93/08/11  14:22:14  czis303
# Add copyright notice.
# Allow caller to specify xterm options.
#
# Revision 1.2  93/07/13  12:05:55  czis303
# New -r option allows specification of remote directory containing X binaries.
# New -d option allows specification of alternate DISPLAY variable.
# ksh-specific syntax changed to be Bourne shell compatible.
# Host name is inserted into DISPLAY variable on workstations.
#
#
#==============================================================================

#-----------------------------------CONFIGURATION------------------------------
# if the remote-shell command on your system is called 'remsh' then change
# rsh to remsh.
RSH=rsh

# This is a KornShell script, but the only ksh feature it uses is getopts. If
# you don't have ksh, but do have getopts then try running it under the
# Bourne shell (by changing the top line).

# By default the script assumes that xterm and xauth on the remote system live
# in /usr/bin/X11 . This is not universally true, so you can change it with
# the -r parameter.

# Some systems (e.g. convexes) have a command called 'execqt', specially
# designed for starting X clients without leaving an rsh process waiting on
# the local system. This script includes code to take advantage of this
# feature, but it will still work without. Set $EXECQT_OPTION to
#       'no'    ==> disable this feature
#       'list'  ==> use execqt for remote machines in $EXECQT_LIST
#       'check' ==> check at runtime whether execqt supported (this will add
#                   to execution time)
#EXECQT_OPTION=list
#EXECQT_LIST="pluto neptune io"      # this is the list used at ULCC
EXECQT_OPTION=no
EXECQT_LIST=""      # this is the list used at ULCC

# The script has been successfully used from the following systems:
#       ConvexOS (ksh), SGI IRIX (ksh), SunOS (sh).
# Target systems include ConvexOS, SGI IRIX, SunOS and Cray UNICOS.
#------------------------------------------------------------------------------
usage=\
" rxterm [-d display] [-l username] [-r remoteXdirectory] hostname [xtermopts]"

# set defaults for command-line options.
remuser=$USER
remXdir=/usr/bin/X11:/usr/openwin/bin
remXld=/usr/lib:/usr/openwin/lib
#
#       Parse the command options
ERRFLAG=OK
OPTIND=1
while getopts d:l:r: OPTION
do
    case $OPTION in
    d)  DISPLAY=$OPTARG;;
    l)  remuser=$OPTARG;;
    r)  remXdir=$OPTARG;;
    \?) ERRFLAG=BAD;;
    esac
done
shift `expr $OPTIND - 1`
#
# Exit with a usage message if the syntax is wrong. In this particular case,
# we insist on at least one operand after the options.
if [ $ERRFLAG != OK -o $# -eq 0 ]
then
    echo 2>&1 "$0: usage:"
    echo 2>&1 "$usage"
    exit 1
fi

remhost=$1
shift
# set up the xterm options. If there are quoted strings we must insert real
# quote marks to ensure they get passed through rsh to xterm.
xtermopts=""

do
    xtermopts="$xtermopts '$opt'"
done

# make sure DISPLAY variable set
if [ -z "$DISPLAY" ]
then
        echo >&2 "$0: DISPLAY variable not set"
        exit 2
fi

# if DISPLAY is set to something like :0.0 then prefix it with host name. This
# is useful on workstation consoles.
case $DISPLAY in
:*|unix:*) DISPLAY=`hostname``expr $DISPLAY : ".*\(:.*\)"`;;
esac

# Check whether to use execqt feature.

EXECQT_CMD=""   # assume not.
EXECQT_PATH=$remXdir/execqt
case "$EXECQT_OPTION" in
no)
    ;;
list)
    for h in $EXECQT_LIST
    do
        if [ "$h" = "$remhost" ]
        then
            EXECQT_CMD=$EXECQT_PATH
            break;
        fi
    done
    ;;
check)
    stat=`$RSH $remhost -n -l $remuser "test -x $EXECQT_PATH && echo YES"`
    [ "$stat" = YES ] && EXECQT_CMD=$EXECQT_PATH
    ;;
*)
    echo >&2 "$0: internal error, bad configuration of EXECQT_OPTION"
    exit 1
    ;;
esac

# Now do the real business. (This area edited on 24/04/03 by eedmit)
{
    # authorise remote user to access this display.
    xauth extract - $DISPLAY \
        | $RSH $remhost -l $remuser "env LD_LIBRARY_PATH=$remXld:$LD_LIBRARY_PATH PATH=$remXdir:$PATH xauth merge -"
    # execute the xterm command
    $RSH $remhost -l $remuser -n \
        "umask 022 < /dev/null >&! /dev/null; \
        env LD_LIBRARY_PATH=$remXld:$LD_LIBRARY_PATH PATH=$remXdir:$PATH $EXECQT_CMD xterm -ls -T '$remhost xterm' \
            -n $remhost -display $DISPLAY $xtermopts \
            < /dev/null > /dev/null &"

Quote:} &

--
Michael Tosch
IT Specialist
HP Managed Services Germany
Phone +49 2407 575 313

 
 
 

1. Automatically setting X display, propagating environment vars


   CJB> To work over any number of hops, the best thing is to be able
   CJB> to send some kind of value over rlogin.  In some later version
   CJB> of Unix I would like to see the ability to selectively
   CJB> propagate certain environment variables such as DISPLAY, as
   CJB> this would solve this entire problem.

   Chris- This is a known problem with not many nice solutions.  The best
   workaround I found is to encapsulate the DISPLAY variable with the
   TERM variable, which /is/ passed between rlogin sessions.

If your home directory is shared over NFS or in any other way, you can
pass information through some file, say ~/.display, creating and
removing it at right moments of time (this is how I set my DISPLAY,
and it works fine, including any number of remote logins and even [why
would you do that?] circular logins).
--
Stanislav Shalunov

URL: http://math.wisc.edu/~shalunov/
PGP key fingerprint =  62 36 7E A3 D4 D0 1D 88  E0 21 F4 0A 0D 93 8E 12

2. ? Linux community manage vs. chaos ?

3. payment gateway

4. Is it possible to automatically set DISPLAY variable for X?

5. Using Groff/Tbl

6. Setting DISPLAY variable automatically in CSH

7. write() errors in Sol2.5.1, on Sun Ultra 1.

8. Is it possible to automatically set the DISPLAY variable?

9. Setting DISPLAY variable automatically

10. Set X DISPLAY variable automatically

11. automatically set the DISPLAY variable

12. Setting the DISPLAY Environment variable