[comp.windows.x] rlogin and the DISPLAY variable

mike%aleytys@UUNET.UU.NET (Michael Kent) (10/16/90)

I appologize if this is a FAQ, but:

I need to rlogin to a remote X Workstation from my local X Workstation,
and have the DISPLAY environmental variable properly set so that any
X apps I run on the remote machine will display on my local machine.
The setting of DISPLAY must happen without operator intervention, and
must be correct no matter which of several local machines rlogin to the
remote machine.

Using the remote shell command is out, since the primary app to be run
on the remote machine is interactive in the manner of 'vi', and is a
'tty'-based app which is best run via rlogin.  Having the user's profile
set DISPLAY is out, as the user can be logging in from several different
local machines.

Any ideas?
-- 
Michael Kent			INTERNET: mike@aleytys.uu.net
Center for M.C.E.		UUCP:     ...!{uunet, uflorida}!aleytys!mike
2521 N.W. 57th Pl		MA BELL:  +1-904-335-1573
Gainesville, Fl  32606		"...yes, we have no bananas..."

soh@shiva.trl.oz (kam hung soh) (10/17/90)

Here's my hack to set the DISPLAY environment on the remote machine:

	rsh -n machine_name "setenv DISPLAY `hostname`:0.0; xprogram" &

I can't use $DISPLAY since mine is set to unix:0.0 to speed up the
display on my machine.  I suppose this would break if you had more
than one screen on your machine.  I'm running X on a SparcStation.

-----
Soh, Kam Hung      email: h.soh@trl.oz.au     tel: +61 03 541 6403 
Telecom Research Laboratories, P.O. Box 249, Clayton, Victoria 3168, Australia 

mouse@LARRY.MCRCIM.MCGILL.EDU (10/17/90)

> I need to rlogin to a remote X Workstation from my local X
> Workstation, and have the DISPLAY environmental variable properly set
> so that any X apps I run on the remote machine will display on my
> local machine.  The setting of DISPLAY must happen without operator
> intervention, and must be correct no matter which of several local
> machines rlogin to the remote machine.

The solution I use is to use xrlogin instead of rlogin, and run
xrlogind on the remote machine.

xrlogin and xrlogind are programs I wrote.  xrlogin packages $TERM and
$DISPLAY up into a string, stuffs it into $TERM, and execs rlogin.
xrlogind recognizes a TERM variable of the special format produced by
xrlogin and unpacks it into setenv commands (I use a csh-based shell).

Thus, my .cshrc everywhere contains

	eval `xrlogind`

and if I use xrlogin to log in remotely everything works.

(I am describing the technique rather than offering code because the
code depends on local include files and library routines to such an
extent that I don't feel up to getting it in releasable shape.  If you
want the code anyway, drop me a line.)

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

karlton@sgi.com (Phil Karlton) (10/18/90)

In article <9010170525.AA09576@Larry.McRCIM.McGill.EDU>, mouse@LARRY.MCRCIM.MCGI
LL.EDU writes:
|> The solution I use is to use xrlogin instead of rlogin, and run
|> xrlogind on the remote machine.
|> xrlogin and xrlogind are programs I wrote.  xrlogin packages $TERM and
|> $DISPLAY up into a string, stuffs it into $TERM, and execs rlogin.
|> xrlogind recognizes a TERM variable of the special format produced by
|> xrlogin and unpacks it into setenv commands (I use a csh-based shell).

I do a similar sort of thing, but don't use any extra scripts that
have to be passed from machine to machine. I use a "%" character as
the separator for the TERM and DISPLAY parts shoved into the TERM
environment variable (the only useful one that the rlogin protocol
transmits).

I alias rlogin to the appropriate value at shell startup time. It does
not get re-evaluated each time. There may be more efficient ways to do
the parsing, but this does work.

Here are some fragments from my .cshrc.
====================================================================
set machine=`/usr/bsd/hostname`
set domain=`/usr/bin/domainname`

if ($?prompt) then

  if ( $TERM =~ *\%* ) then
    setenv DISPLAY `echo $TERM | sed '/^.*%/s///'`
    set term=`echo $TERM | sed '/%.*$/s///'`
  endif

  switch ( $DISPLAY )
      case "":
      case ":0":
      case ":0.0":
      case "unix:0":
      case "unix:0.0":
      case "localhost:0":
      case "localhost:0.0":
	alias rlogin "(setenv TERM $term%${machine}.${domain}:0 ; \
		/usr/bsd/rlogin \!* )"
	breaksw
    default
	alias rlogin "(setenv TERM $term%$DISPLAY ; /usr/bsd/rlogin \!* )"
  endsw

endif

gildea@ALEXANDER.BBN.COM (Stephen Gildea) (10/18/90)

Use xon (distributed with R4 in contrib/clients/scripts/), which
handles passing the DISPLAY value to the remote system.  In your
case, you want a command line something like this:

xon remotehost xterm -e vi


 < Stephen				Bolt Beranek and Newman Inc.
   gildea@bbn.com			Cambridge, Massachusetts

iant@hpopd.HP.COM (Ian Thornton) (10/18/90)

> I need to rlogin to a remote X Workstation from my local X Workstation, and 
> have the DISPLAY environmental variable properly set ...

> The setting of DISPLAY must happen without operator intervention ...

> Using the remote shell command is out, since the primary app to be run on the
> remote machine is interactive ...

	You're right that you can't use 'remsh' but if you have 'xrsh' on your
	X machines, this should serve your purposes. 'xrsh' is a front-end to
	'rsh' or 'remsh' and makes sure that the value of DISPLAY is 
	propogated to the remote session automatically. To login on remote
	machines I use the line ...

	xrsh <rmachine> /usr/bin/X11/xterm -e ksh .xprofile

	where <rmachine> is the name of the remote machine,
	.xprofile is a file I keep in the HOME directory of each remote
	machine. It is a copy of .profile except any references to DISPLAY
	are removed and a line is added at the end containing ...

	exec ksh

	
	This setup enables me to execute any X application on any X workstation
	from any other workstation.
	Hope this helps ...

				Ian Thornton (iant@hpopd.hp.com)

duanev@radar.ACA.MCC.COM (Duane Voth) (10/19/90)

In article <m0iOhip-00013UC@aleytys.uu.net>, mike%aleytys@UUNET.UU.NET (Michael Kent) writes:
> I need to rlogin to a remote X Workstation from my local X Workstation,
> and have the DISPLAY environmental variable properly...
>
> Having the user's profile
> set DISPLAY is out, as the user can be logging in from several different
> local machines.

I've successfully been overloading $term.  I can start from any machine,
rlogin as far as I want, and the new shell will always set $DISPLAY
to the machine I started from.  This works fine so long as
all target accounts contain .cshrc code to reset $TERM before
it is used for anything.  If you are a sysop this shouldn't be a problem.
Sorry, sh/ksh/bash users, I've not tried this with other shells.

Here are the useful parts of a .cshrc:
--------------------

if ( "$term" =~ *%* ) then              # check for special variables
        eval `echo $term | sed '/[0-9A-Za-z]*%/s///'`
        set term=`echo $term | sed '/%.*/s///'`
endif

alias   _to     'set term=${term}%\!*'


if ($term == "xterm") then
        if ($?RDISPLAY) then
                if ( "$RDISPLAY" =~ ${hostname}* ) then
                        setenv DISPLAY unix:0
                else
                        setenv DISPLAY $RDISPLAY
                        echo "remote display $RDISPLAY"
                endif
        else
                setenv DISPLAY unix:0
                setenv RDISPLAY ${hostname}:0
        endif

        alias rlogin    '(_to "setenv RDISPLAY $RDISPLAY"; /usr/ucb/rlogin \!*)'
endif

--------------------
-- 
--- duane voth                                         duanev@mcc.com
----    {uunet,harvard,gatech,pyramid}!cs.utexas.edu!milano!pp!duanev
--- ALL systems are arbitrary!  Effectiveness is the measure of Truth
--