home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / shell / 5133 < prev    next >
Encoding:
Internet Message Format  |  1992-12-22  |  3.3 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!crcnis1.unl.edu!cse!sanjiv
  2. From: sanjiv@cse.unl.edu (Sanjiv K. Bhatia)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: Opening up remote xterm windows?
  5. Date: 22 Dec 1992 18:21:47 GMT
  6. Organization: University of Nebraska--Lincoln    
  7. Lines: 112
  8. Distribution: world
  9. Message-ID: <1h7mbrINNct9@crcnis1.unl.edu>
  10. References: <1992Dec20.215237.3151@spectrum.xerox.com>
  11. NNTP-Posting-Host: cse.unl.edu
  12.  
  13. Try the following script called xrsh.
  14.  
  15. ----- cut here -----
  16. #!/bin/sh
  17. # xrsh - launch X applications on a remote host.
  18. #
  19. # Usage: xrsh [-v | -vv] [-l userid] [-display display] host [command]
  20. #   If command is omitted, xrsh launches an xterm on the remote host.
  21. #   The -v option turns on verbose mode.  This is useful in finding
  22. #     out why the xrsh command didn't work.
  23. #   The -vv option turns on very verbose mode.  This is useful in finding
  24. #     out why the xrsh command really didn't work.
  25. #   The -l option selects the userid to login as on the remote system.
  26. #   The -display option overrides the DISPLAY environment variable.
  27. #   See the Caveats at the end of this file.
  28. #
  29. #   This version by Felix Lee and Scott Schwartz
  30. #
  31.  
  32. # Do arguments...
  33. QUIETLY="</dev/null >/dev/null 2>&1"
  34. LOGIN=""
  35. while expr "$1" : '-.*' >/dev/null
  36. do
  37.     # ... Are we verbose?
  38.     case $1 in
  39.     -vv*)    shift; QUIETLY=""; set -x
  40.         ;;
  41.     -v*)    shift; QUIETLY=""
  42.         ;;
  43.     esac
  44.  
  45.     # ... Override display?
  46.     case $1 in
  47.     -d*)    shift; DISPLAY=$1; shift ;;
  48.     esac
  49.  
  50.     # ... Alternate login?
  51.     case $1 in
  52.     -l*)    shift; LOGIN="-l $1"; shift ;;
  53.     esac
  54. done
  55.  
  56. # ... Set DISPLAY to the local host name, if necessary.
  57. WIN=`expr x$DISPLAY : x".*:\(.*\)"`
  58. case $DISPLAY in
  59. ''|:*|unix:*)
  60. #    DISPLAY=`(domainname) 2>/dev/null` &&
  61. #        DISPLAY=`hostname`.${DISPLAY}:${WIN} ||
  62. #        DISPLAY=`hostname`:${WIN}
  63.     DISPLAY=`hostname`.`awk '{print $2} {exit}' /etc/resolv.conf`:0.0
  64.     ;;
  65. esac
  66. export DISPLAY
  67.  
  68. # ... Fix path to include X.
  69. case $PATH in
  70. *X11*) ;;
  71. *) PATH=$PATH:/usr/bin/X11; export PATH;;
  72. esac
  73.  
  74. # ... With no arguments, just start up an xterm.
  75. case $# in
  76. 0)    eval 'xterm -n "`hostname`" ${1+"$@"}' $QUIETLY '&'
  77.     exit
  78. esac
  79.  
  80. # ... First argument is the host.
  81. HOST=$1
  82. shift
  83.  
  84. # ... Enable access for the host.
  85. eval 'xhost +$HOST >/dev/null' $QUIETLY
  86.  
  87. # ... If no command is given, start an xterm.
  88. case $# in
  89. 0)    COMMAND="xterm"
  90.     ;;
  91. *)    COMMAND="$@"
  92.     ;;
  93. esac
  94.  
  95. # ... Try to recognize an xterm command and push a name option on.
  96. set $COMMAND
  97. case $1 in
  98. xterm|*/xterm)
  99.     COMMAND="$1 -n `echo $HOST | sed -e 's/\..*//'`\ "
  100.     shift
  101.     COMMAND="$COMMAND $*"
  102. esac
  103.  
  104. # ... Fire away.
  105. rsh $HOST $LOGIN -n \
  106. "sh -c 'DISPLAY=$DISPLAY;PATH=$PATH export DISPLAY PATH;($COMMAND) $QUIETLY &'"
  107. exit
  108.  
  109. # Caveats:
  110. #   Don't try piping to xrsh.  It won't work.
  111. #   Don't try to use quotes in the command.  It's really hairy.
  112. #   xrsh makes a (probably misguided) attempt to recognize "xterm"
  113. #     commands and insert a "-name" specification for you.  This
  114. #     fails ignominiously if you say "xrsh foo 'xterm; xterm'".
  115. #     You're better off putting "-name" in yourself.
  116. #   "xrsh foo" is not quite the same as "xrsh foo xterm".  The
  117. #     first gives xterm the "-ls" option, the second does not.
  118.  
  119.  
  120. --
  121. Sanjiv K. Bhatia        Department of Mathematics & Computer Science
  122. sanjiv@redbird.umsl.edu        University of Missouri -- St. Louis
  123. voice: (314)-553-6520        8001 Natural Bridge Road
  124.                 St. Louis, MO 63121-4499
  125.