[comp.unix.questions] Can I pass variables to rlogin?

umh@vax5.cit.cornell.edu (04/15/91)

I am very surprised this is not part of FAQ? Is no-one else as ambitious as me?
The problem is that we have a number of machines (Sun3, SparcStation, RS6000)
on three different NFS networks, all running X-Windows. Now often one will try
to rlogin from say an RS6000 to a Sparc in order to execute a Sparc binary. And
well and good- we type rlogin host and get a terminal to the Sparc. However, if
the binary we wish to execute is an X program we then have to type, at the
Sparc, setenv DISPLAY rs6000:0, which becomes a right pain the 10 000th time
you've done it.

So my question to the net is how can one get around this? At present I have
this really ugly kludge with temporary files that .login and .xinitrc look at
and possibly change. This works so-so across a single NFS network, but to make
it work across three requires rlogin be aliased to something with rcp in it,
there are horrible synchroniztion problems- etc. 
The sort of nice way I'd like to do this would be either
be able to pass environment variables to rlogin (like passing #defines to cc)
so I could say rlogin host -Dfrom=`hostname` (then alias that, of course)
failing something that general, can I at least somehow test in my .login if
this .login is being started as an rlogin from a remote machine, and what that
machine's name is?

Or am I barking up the wrong tree? Is this nicely fixed by some X magic, not
using UNIX at all?

If anyone has been able to do something like this, please tell me. I'll
summarize any methods I find, of general interest.

Maynard Handley

jc@condor.bu.edu (James Cameron) (04/16/91)

>>>>> On 14 Apr 91 23:10:50 GMT, umh@vax5.cit.cornell.edu said:

[...deleted lines concerning how to work on several computers in X windows...]

umh> Or am I barking up the wrong tree? Is this nicely fixed by some X magic, not
umh> using UNIX at all?

umh> If anyone has been able to do something like this, please tell me. I'll
umh> summarize any methods I find, of general interest.

umh> Maynard Handley


The solution I use is the script which follows; I did not write it and
I am unsure of who did, but there are many similiar to this one out
there.  This should completely solve your problem.

---xshell---
#!/bin/csh -f
#
#	this sets up an xterm on the remote machine at the same time
#	performing a xhost for the remote machine on the display machine
#
#	First, find the name of the display
#
set command=$0
if ( $#argv  == 0 ) then
	echo Usage: $command:t hostname
	exit 1
endif
set remotehost=$1
shift
set displayhost=`printenv DISPLAY | sed -e 's/:.*//'`
#
#	Now we need to see if this has the right name
#
switch ( $displayhost )

	case	unix:	# display on the local host
			xhost $remotehost
			if ( $status != 0 ) then
				echo xhost failed on local machine
				exit 1
			endif
			set displayhost=`hostname`
			breaksw

	case	"":	# not an X device
			echo The environment variable DISPLAY is not
			echo set. You must issue the command \"$command:t\"
			echo from an X device.
			exit 1
			breaksw

	default:	# display on a remote host
			echo "setenv DISPLAY ${displayhost}:0.0 ; xhost $remotehost" | rsh $displayhost csh -t
			if ( $status != 0 ) then
				echo xhost failed on machine \"$displayhost\".
				exit 1
			endif
			breaksw
endsw

rsh $remotehost xterm -display ${displayhost}:0.0 -ls -n $remotehost $argv &

exit 0
--
					-- James Cameron  (jc@raven.bu.edu)

Signal Processing and Interpretation Lab.  Boston, Mass  (617) 353-2879
------------------------------------------------------------------------------
"But to risk we must, for the greatest hazard in life is to risk nothing.  For
the man or woman who risks nothing, has nothing, does nothing, is nothing."
	(Quote from the eulogy for the late Christa McAuliffe.)