home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2634 < prev    next >
Internet Message Format  |  1991-01-30  |  1KB

  1. From: maart@cs.vu.nl (Maarten Litmaath)
  2. Newsgroups: comp.unix.programmer,alt.sources
  3. Subject: ersh - rsh frontend hack returning exit status of remote cmd
  4. Message-ID: <8877@star.cs.vu.nl>
  5. Date: 30 Jan 91 00:26:48 GMT
  6.  
  7. #!/bin/sh
  8. # @(#)ersh 2.4 91/01/30 Maarten Litmaath
  9. # This rsh front-end returns the exit status of the remote command.
  10. # It works OK with sh/csh-compatible shells on the remote (!) side.
  11. # If there is no remote command present, /usr/ucb/rlogin is invoked.
  12. # Usage: see rsh(1).
  13.  
  14. unset hostname lflag nflag user
  15.  
  16. case $1 in
  17. -l)
  18.     ;;
  19. *)
  20.     hostname=$1
  21.     shift
  22. esac
  23.  
  24. case $1 in
  25. -l)
  26.     lflag=-l
  27.     user=$2
  28.     shift 2
  29. esac
  30.  
  31. case $1 in
  32. -n)
  33.     nflag=-n
  34.     shift
  35. esac
  36.  
  37. case $hostname in
  38. '')
  39.     hostname=$1
  40.     shift
  41. esac
  42.  
  43. case $# in
  44. 0)
  45.     exec /usr/ucb/rlogin $lflag ${user+"$user"} "$hostname"
  46. esac
  47.  
  48. AWK='
  49.     NR > 1 {
  50.         print prev;
  51.         prev = $0;
  52.         prev1 = $1;
  53.         prev2 = $2;
  54.     }
  55.     NR == 1 {
  56.         prev = $0;
  57.         prev1 = $1;
  58.         prev2 = $2;
  59.     }
  60.     END {
  61.         if (prev1 ~ /[0-9]*[0-9]0/)
  62.             exit(prev1 / 10);
  63.         if (prev1 == "0")
  64.             exit(prev2);
  65.         print prev;
  66.         exit(1);
  67.     }
  68. '
  69.  
  70. exec 3>&1
  71.  
  72. /usr/ucb/rsh "$hostname" $lflag ${user+"$user"} $nflag \
  73.     "(${*-:}); sh -c '"'echo "$0 $1" >&2'\'' $?0 "$status"' \
  74.     2>&1 >&3 3>&- | awk "$AWK" >&2 3>&-
  75. --
  76. Temporary files like /tmp/sh$$ are an abomination.
  77.