home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gwm18a.zip / contrib / rxterm / rxterm.script < prev   
Text File  |  1995-07-03  |  3KB  |  136 lines

  1. #!/bin/sh
  2.  
  3. usage='Usage:    rx <remhost> <X-command> [<args>]
  4.     rxterm <remhost> [<args>]
  5.     rxload <remhost> [<args>]
  6.     rxcmdtool <remhost> [<args>]
  7.  
  8. Executes <X-command> on <remhost> and redirects its standard and error output 
  9. to the file $HOME/.rx.log on <remhost>.
  10. The connection to <remhost> terminates as soon as <X-command> is launched, not
  11. when <X-command> terminates.
  12. The user should have permission to use rsh from the current host to <remhost>
  13. and to execute X clients on <remhost>.  See rsh, xhost.
  14. '
  15.  
  16. [ $# = 0 ] && { echo "$usage" >&2; exit 1; }
  17. case $1 in
  18.   -* )
  19.     echo "$usage" >&2; exit 1;;
  20. esac
  21.  
  22. remhost=$1; shift; comm="$*"
  23.  
  24. case $0 in
  25.   *rxload )
  26.     comm="xload $comm"
  27.     ;;
  28.   *rxterm )
  29.     case $comm in
  30.       *-e* )
  31.     # Extract the entry name of the command to execute
  32.     name=`echo $comm | sed 's/.*-e[     ]*\([^     ]*\).*/\1/'`
  33.     if [ -z "$name" ]
  34.         then
  35.         echo "missing command name for -e switch"
  36.         exit 1
  37.     fi
  38.         name=`basename $name`@$remhost        # Ex: emacs@mirsa
  39.     ;;
  40.       * )
  41.         # Just the machine name
  42.         name=$remhost
  43.     ;;
  44.     esac
  45.     # Always login shell!
  46.     comm="xterm -ls -T $name $comm"
  47.     ;;
  48.    *rxcmdtool )
  49.     case $comm in
  50.       *-e* )
  51.     # Extract the entry name of the command to execute
  52.     name=`echo $comm | sed 's/.*-e[     ]*\([^     ]*\).*/\1/'`
  53.     if [ -z "$name" ]
  54.         then
  55.         echo "missing command name for -e switch"
  56.         exit 1
  57.     fi
  58.         name=`basename $name`@$remhost        # Ex: emacs@mirsa
  59.     ;;
  60.       * )
  61.         # Just the machine name
  62.         name=$remhost
  63.     ;;
  64.     esac
  65.     # Always login shell!
  66.     comm="cmdtool -label $name $comm"
  67.     ;;
  68. esac
  69.  
  70. # Current Host
  71. hostname=${HOSTNAME-`hostname || /usr/5bin/uname -n 2> /dev/null`} 
  72.  
  73. [ -z "$DISPLAY" ] && DISPLAY=unix:0     # Default for DISPLAY
  74. IFS=:
  75. set $DISPLAY
  76. IFS='     
  77. '
  78. xhostname=$1 xscreen=$2
  79. if [ -z "$xscreen" ]
  80. then
  81.     xscreen=$xhostname
  82.     xhostname=$hostname
  83. fi
  84. [ "$xhostname" = unix ] && xhostname=$hostname
  85.  
  86. case $remhost in
  87.   *.*.* )
  88.     # May be a different domain: we have to find the full name of the xhostname
  89.     # Search for the name server, then N.I.S, then /etc/hosts
  90.     oldpath=$PATH
  91.     PATH=/usr/etc:/usr/ucb:/etc:/bin:/usr/bin:/usr/etc/yp
  92.     host=`(nslookup $xhostname) 2> /dev/null | \
  93.         sed -n 's/Name:[         ]*\(.*\)/\1/p'`
  94.     if [ -z "$host" ]
  95.     then
  96.     host=`(ypmatch $xhostname hosts) 2> /dev/null | \
  97.         sed -n 's/[^     ]*[     ]*\([^     ]*\).*/\1/p'`
  98.     fi
  99.     if [ -z "$host" ]
  100.     then
  101.     host=`sed -n /$xhostname/'s/[^     ]*[     ]*\([^     ]*\).*/\1/p' \
  102.         /etc/hosts`
  103.     fi
  104.     xhostname=$host
  105.     PATH=$oldpath
  106. esac
  107.  
  108. # For efficiency, use of unix:0 for local clients
  109. if [ "$xhostname" = "$remhost" ]
  110. then
  111.     DISPLAY=unix:$xscreen
  112. else
  113.     DISPLAY=$xhostname:$xscreen
  114. fi
  115.  
  116. # Rshd  open one file-descriptor (number 7 often) and does'nt terminate
  117. # before it is closed!!!!
  118.  
  119. # List of variables to export through rsh if they are defined
  120. vars='PATH DISPLAY XENVIRONMENT XAPPLRESDIR PRINTER LD_LIBRARY_PATH OPENWINHOME GUIDEHOME'
  121. env= var= val=
  122. for var in $vars
  123. do
  124.     eval val=\$$var
  125.     [ -n "$val" ] &&  env="${env}$var=$val;export $var;"
  126. done
  127.  
  128. xhost +$remhost  > /dev/null
  129.  
  130. # Using rsh even localy permits to unattach the xcommand from the 
  131. # current tty if any
  132. exec rsh $remhost -n "exec sh -c \"    $env $comm < /dev/null > .rx.log 2>&1 \
  133.             3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 9>&1 \
  134.             3>&- 4>&- 5>&- 6>&- 7>&- 8>&- 9>&- &\" "
  135.  
  136.