SUMMARY: the DISPLAY environment on remote machines

From: Clive Haworth (chaworth@jpmorgan.com)
Date: Thu Dec 16 1993 - 17:55:22 CST


Original Posting
----------------

> Here's something I came across recently, wish may be of some use
> to someone. I seem to remember someone asking for this - but have
> forgotten who & when.
>
> Basically adding this to your .login file will set the DISPLAY
> environment automatically to your own display. It seems to work
> OK but I haven't tested it extensively.
>
> #
> # Set DISPLAY automatically on login (csh version).
> #
> set COMEFROM = \
> `who am i | awk '{print $6}' | tr -d '()' | awk -F. '{print $1}'`
> if ( $#COMEFROM == 1 ) then
> setenv DISPLAY ${COMEFROM}:0
> endif
> unset COMEFROM

I had a good response to this one, with lots of ideas.
Many thanks to the following people that responded to this:

 James D. Watson <JW1675A@american.edu>
 Ben Gross <gross@caterer.beckman.uiuc.edu>
 Calum Mackay <calum.mackay@mrc-biostatistics.cambridge.ac.uk>
 Dave Hightower <hightowr@utah.afwc.af.mil>
 James J Dempsey <jjd@spserv.bbn.com>
 Peter.Samuel@nms.otc.com.au (Peter Samuel)
 Yves Morin <Yves.Morin@BComeau.Hydro.Qc.CA>
 bern@kleopatra.Uni-Trier.DE (Jochen Bern)
 fgreco@lehman.com (Frank Greco)
 fischer@vlab.nsd.fmc.com (Scott W Fischer)
 hushing@gdwest.gd.com (Sumner Hushing)
 leon@orbot.co.il (Leon Koll)
 mch@sqwest.wimsey.bc.ca (Mark C. Henderson)
 aluxpo!nlf (Nelson Fernandez)
 olav.lerbrekk@geologi.uio.no (Olav Lerbrekk)
 tom@yac.llnl.gov

Most people pointed out that the trick only works for the first hop.
The next hop sets the DISPLAY incorrectly.

Others pointed out that 'who' is fairly specific to whatever breed of
UNIX you're running. Scott W Fischer sent a C program to emulate the
above script, though this still suffers from the hop problem.

Nelson Fernandez suggested packing information into the TERM environment
variable to solve this problem. Also xlogin or xrsh was suggested.

My preferred choice was suggested by Peter Samuel:

> A better (but still not perfect way) is to save the value of $DISPLAY
> as generated by ~/.xinitrc or ~/.xsession in a file ~/.display and then
> get your shell to read the file on login and set $DISPLAY from the file's
> contents.
>
> This method works very well - regardless of the number of hops you
> make around your network.
> It fails if you are logged into two different X displays
>
> simultaneously because the second login will overwrite the contents of
> ~/.display.

------------------------------------------------------------------------
I chose a simple form of this - to create a file .Xdisplay
in my home directory:

#
# The display to view X applications on when remotely logged in.
#
<host>:0

Then add these lines to the login script:

if ( -f $HOME/.Xdisplay ) then
        #
        # Set the DISPLAY environment variable if possible.
        # Allow comment characters '#' at the start of a line.
        #
        setenv DISPLAY "`egrep -v '^#' $HOME/.Xdisplay`"
endif
------------------------------------------------------------------------

Thanks again for the response !!

Clive Haworth
chaworth@jpmorgan.com



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:08:33 CDT