home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!crcnis1.unl.edu!cse!sanjiv
- From: sanjiv@cse.unl.edu (Sanjiv K. Bhatia)
- Newsgroups: comp.unix.shell
- Subject: Re: Opening up remote xterm windows?
- Date: 22 Dec 1992 18:21:47 GMT
- Organization: University of Nebraska--Lincoln
- Lines: 112
- Distribution: world
- Message-ID: <1h7mbrINNct9@crcnis1.unl.edu>
- References: <1992Dec20.215237.3151@spectrum.xerox.com>
- NNTP-Posting-Host: cse.unl.edu
-
- Try the following script called xrsh.
-
- ----- cut here -----
- #!/bin/sh
- # xrsh - launch X applications on a remote host.
- #
- # Usage: xrsh [-v | -vv] [-l userid] [-display display] host [command]
- # If command is omitted, xrsh launches an xterm on the remote host.
- # The -v option turns on verbose mode. This is useful in finding
- # out why the xrsh command didn't work.
- # The -vv option turns on very verbose mode. This is useful in finding
- # out why the xrsh command really didn't work.
- # The -l option selects the userid to login as on the remote system.
- # The -display option overrides the DISPLAY environment variable.
- # See the Caveats at the end of this file.
- #
- # This version by Felix Lee and Scott Schwartz
- #
-
- # Do arguments...
- QUIETLY="</dev/null >/dev/null 2>&1"
- LOGIN=""
- while expr "$1" : '-.*' >/dev/null
- do
- # ... Are we verbose?
- case $1 in
- -vv*) shift; QUIETLY=""; set -x
- ;;
- -v*) shift; QUIETLY=""
- ;;
- esac
-
- # ... Override display?
- case $1 in
- -d*) shift; DISPLAY=$1; shift ;;
- esac
-
- # ... Alternate login?
- case $1 in
- -l*) shift; LOGIN="-l $1"; shift ;;
- esac
- done
-
- # ... Set DISPLAY to the local host name, if necessary.
- WIN=`expr x$DISPLAY : x".*:\(.*\)"`
- case $DISPLAY in
- ''|:*|unix:*)
- # DISPLAY=`(domainname) 2>/dev/null` &&
- # DISPLAY=`hostname`.${DISPLAY}:${WIN} ||
- # DISPLAY=`hostname`:${WIN}
- DISPLAY=`hostname`.`awk '{print $2} {exit}' /etc/resolv.conf`:0.0
- ;;
- esac
- export DISPLAY
-
- # ... Fix path to include X.
- case $PATH in
- *X11*) ;;
- *) PATH=$PATH:/usr/bin/X11; export PATH;;
- esac
-
- # ... With no arguments, just start up an xterm.
- case $# in
- 0) eval 'xterm -n "`hostname`" ${1+"$@"}' $QUIETLY '&'
- exit
- esac
-
- # ... First argument is the host.
- HOST=$1
- shift
-
- # ... Enable access for the host.
- eval 'xhost +$HOST >/dev/null' $QUIETLY
-
- # ... If no command is given, start an xterm.
- case $# in
- 0) COMMAND="xterm"
- ;;
- *) COMMAND="$@"
- ;;
- esac
-
- # ... Try to recognize an xterm command and push a name option on.
- set $COMMAND
- case $1 in
- xterm|*/xterm)
- COMMAND="$1 -n `echo $HOST | sed -e 's/\..*//'`\ "
- shift
- COMMAND="$COMMAND $*"
- esac
-
- # ... Fire away.
- rsh $HOST $LOGIN -n \
- "sh -c 'DISPLAY=$DISPLAY;PATH=$PATH export DISPLAY PATH;($COMMAND) $QUIETLY &'"
- exit
-
- # Caveats:
- # Don't try piping to xrsh. It won't work.
- # Don't try to use quotes in the command. It's really hairy.
- # xrsh makes a (probably misguided) attempt to recognize "xterm"
- # commands and insert a "-name" specification for you. This
- # fails ignominiously if you say "xrsh foo 'xterm; xterm'".
- # You're better off putting "-name" in yourself.
- # "xrsh foo" is not quite the same as "xrsh foo xterm". The
- # first gives xterm the "-ls" option, the second does not.
-
-
- --
- Sanjiv K. Bhatia Department of Mathematics & Computer Science
- sanjiv@redbird.umsl.edu University of Missouri -- St. Louis
- voice: (314)-553-6520 8001 Natural Bridge Road
- St. Louis, MO 63121-4499
-