Does anyone have any neat/elegant/clever ways of setting the DISPLAY variable when working in a situation where I may use X in different places and want to run X applications from different remote machines?
Usually I am doing the following:- Logging on to my desktop Linux box called chrisg and starting the X server there.
Running local X client applications on chrisg.
Running remote X client applications on Solaris and other boxes which I want to display on chrisg
OK, so to do the above I can simply hardcode DISPLAY=chrisg:0.0 in my .profile and all will be well.
However.... Sometimes I want to use a different desktop machine at work or I want to work from home. This results in two different requirements:-
The first case (using a different machine at work) means that my hard-coded DISPLAY=chrisg:0.0 will always be wrong.
The second case (working from home) I will be using 'ssh -X' to connect so ssh will be setting the DISPLAY variable and I don't want anything else to change it.
So how is one *supposed* to make this all work? I need some way to get DISPLAY set correctly most of the time, I'd go crazy if I had to set it manually every time I rlogin to another machine here at work. I typically have five or six xterms open to Solaris boxes for example. Currently having it hardcoded in my .profile works 'most of the time' but it's then a big pain sorting out the ssh use because the special ssh value for DISPLAY is lost.
So how is one *supposed* to make this all work? I need some way to get DISPLAY set correctly most of the time, I'd go crazy if I had to set it manually every time I rlogin to another machine here at work. I typically have five or six xterms open to Solaris boxes for example. Currently having it hardcoded in my .profile works 'most of the time' but it's then a big pain sorting out the ssh use because the special ssh value for DISPLAY is lost.
I'm sure there must be some environment variable or other that gets set if you're logging in to your machine remotely that doesn't get set if you log in directly. Set DISPLAY from .profile depending on the value of that variable?
Or... you could grep ps for your /(ba)?sh/ instance and see if it's running on a real vt or not... summat like that.
*clutches at straws*
Steve
On 28-Mar-07 10:47:17, Steve Engledow wrote:
So how is one *supposed* to make this all work? I need some way to get DISPLAY set correctly most of the time, I'd go crazy if I had to set it manually every time I rlogin to another machine here at work. I typically have five or six xterms open to Solaris boxes for example. Currently having it hardcoded in my .profile works 'most of the time' but it's then a big pain sorting out the ssh use because the special ssh value for DISPLAY is lost.
I'm sure there must be some environment variable or other that gets set if you're logging in to your machine remotely that doesn't get set if you log in directly. Set DISPLAY from .profile depending on the value of that variable?
Or... you could grep ps for your /(ba)?sh/ instance and see if it's running on a real vt or not... summat like that.
*clutches at straws*
Steve
I' ve just had a look, using various xterms in which I'm logged in to 3 other machines (2 on my home net, 1 on a remote net) at the results of "set". I'm doing this from home machine 1 called "compo.fort.knox.uk", "fort.knox.uk" being the local name for my home network, not know to the outside world.
Result from "set" executed on home machine 2 invoked from xterm displaying on home machine 1:
DISPLAY=compo.fort.knox.uk:0.0
Result from "set" on home machine 2, similarly invoked:
DISPLAY=compo.fort.knox.uk:0.0
Result from "set" on machine on remote net, similarly invoked (a FreeBSD machine, by the way):
DISPLAY=compo.fort.knox.uk:0.0
However, if I now switch (Ctrl-Alt-F1) to a plain console, and log in to all three remote machines in turn, then in all three cases there is no environment variable DISPLAY.
So DISPLAY gets set remotely if I log in from an xterm, but not if I log in from a text console (non-X). This suggests that there is something in the login sequence which negotiates with the logging-in machine and asks it what its DISPLAY is.
However, despite poking around, I can't find out where this happens!
ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 29-Mar-07 Time: 18:34:44 ------------------------------ XFMail ------------------------------
On 28-Mar-07 10:32:19, Chris G wrote:
Does anyone have any neat/elegant/clever ways of setting the DISPLAY variable when working in a situation where I may use X in different places and want to run X applications from different remote machines?
You could try on the lines of the following, where the context is that you want to set the DISPLAY variable variable on machine A, to which you are logged in from machine B (hence want to run an X app on A and see its X display on machine B).
On machine A, make use of 'who am i' to find out the hostname or IP address of machine B (it's in field 6 of the output of 'who am i', within brackets); hence use this to set the DISPLAY.
Example (I'm currently logged in to A=nessie.mcc.ac.uk from one of my home machines, B, and entering the following from B):
bash$ who am i efh ttyp3 Mar 28 12:16 (88.96.44.206)
bash$ who am i | awk '{print $6}' (88.96.44.206)
bash$ who am i | awk '{print $6}' | tr -d "()" 88.96.44.206
bash$ export DISPLAY=`who am i | awk '{print $6}' | tr -d "()"`:0.0 bash$ echo $DISPLAY 88.96.44.206:0.0
Not that that would really work in my case, since 88.96.44.206 is the IP of my broadband connection, not of any one of my individual home machines (whichever one I'm logged in from, I get the same IP from the remote host):
bash$ /usr/X11R6/bin/xterm _X11TransSocketINETConnect: Can't connect: errno = 61
but that's another issue!
Dunno if that helps ... !! Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 28-Mar-07 Time: 12:49:02 ------------------------------ XFMail ------------------------------
On Wed, Mar 28, 2007 at 11:32:19AM +0100, Chris G wrote:
Does anyone have any neat/elegant/clever ways of setting the DISPLAY variable when working in a situation where I may use X in different places and want to run X applications from different remote machines?
...
So how is one *supposed* to make this all work?
Use ssh everywhere? You mention rlogin; how are you passing around your xauth cookies? (Please tell me the answer isn't "I have xhost + set" unless you work alone and no one else has access to your network.)
J.
On Wed, Mar 28, 2007 at 03:04:39PM +0100, Jonathan McDowell wrote:
On Wed, Mar 28, 2007 at 11:32:19AM +0100, Chris G wrote:
Does anyone have any neat/elegant/clever ways of setting the DISPLAY variable when working in a situation where I may use X in different places and want to run X applications from different remote machines?
...
So how is one *supposed* to make this all work?
Use ssh everywhere? You mention rlogin; how are you passing around your xauth cookies? (Please tell me the answer isn't "I have xhost + set" unless you work alone and no one else has access to your network.)
At work the network is behind a firewall and all the Solaris/Linux machines are development machines with no sensitive personal information so it's fairly relaxed. The Linux boxes use ssh so environment set up is easier there but the old Solaris boxes only have rlogin/rsh. I set up specific machine access using .rhosts and X using 'xhost +name'.
I think I have a reasonable fix for my problem:-
In my .xinitrc I set the DISPLAY variable to `hostname`:0.0
Also in .xinitrc I create a little script (using echo) that will set the DISPLAY variable correctly.
In my .kshenv (also known as .kshrc) file I test to see if DISPLAY is set and, if it isn't, run the script created by .xinitrc.
This will work on all machines where my home directory is visible and won't break ssh DISPLAY setting (the test to see if it's set).
The only cases when it won't work are if I have two X sessions running on different machines (very unlikely) and from machines where my home directory isn't visible which I can probably deal with 'manually'.