home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2131 < prev    next >
Internet Message Format  |  1990-12-28  |  2KB

  1. From: maart@cs.vu.nl (Maarten Litmaath)
  2. Newsgroups: comp.unix.shell,alt.sources
  3. Subject: Re: returning values from an rsh.
  4. Message-ID: <8318@star.cs.vu.nl>
  5. Date: 21 Nov 90 16:13:46 GMT
  6.  
  7. In article <FRIDMAN.90Nov20121605@cs-sun-aa.cs>,
  8.     fridman@cs-sun-aa.cs (fridman) writes:
  9. )
  10. )I need a way for an rsh to return the status of the last
  11. )command that it executed on the remote machine. 
  12.  
  13. : This is a shar archive.  Extract with sh, not csh.
  14. : This archive ends with exit, so do not worry about trailing junk.
  15. : --------------------------- cut here --------------------------
  16. PATH=/bin:/usr/bin:/usr/ucb
  17. echo Extracting 'ersh'
  18. sed 's/^X//' > 'ersh' << '+ END-OF-FILE ''ersh'
  19. X#!/bin/sh
  20. X# @(#)ersh 2.1 89/12/07 Maarten Litmaath
  21. X# this rsh front-end returns the exit status of the remote command
  22. X# works OK with sh/csh-compatible shells on the remote side (!)
  23. X# beware of `funny' chars in `status' when working in sh-compatible shells
  24. X# if there is no remote command present, /usr/ucb/rlogin is invoked
  25. X# usage: see rsh(1)
  26. X
  27. Xhostname=
  28. Xlflag=
  29. Xnflag=
  30. X
  31. Xcase $1 in
  32. X-l)
  33. X    ;;
  34. X*)
  35. X    hostname=$1
  36. X    shift
  37. Xesac
  38. X
  39. Xcase $1 in
  40. X-l)
  41. X    lflag="-l $2"
  42. X    shift 2
  43. Xesac
  44. X
  45. Xcase $1 in
  46. X-n)
  47. X    nflag=-n
  48. X    shift
  49. Xesac
  50. X
  51. Xcase $hostname in
  52. X'')
  53. X    hostname=$1
  54. X    shift
  55. Xesac
  56. X
  57. Xcase $# in
  58. X0)
  59. X    exec /usr/ucb/rlogin $lflag $hostname
  60. Xesac
  61. X
  62. XAWK='
  63. X    NR > 1 {
  64. X        print prev;
  65. X        prev = $0;
  66. X        prev1 = $1;
  67. X        prev2 = $2;
  68. X    }
  69. X    NR == 1 {
  70. X        prev = $0;
  71. X        prev1 = $1;
  72. X        prev2 = $2;
  73. X    }
  74. X    END {
  75. X        if (prev1 ~ /[0-9]*[0-9]0/)
  76. X            exit(prev1 / 10);
  77. X        if (prev1 == "0")
  78. X            exit(prev2);
  79. X        print prev;
  80. X        exit(1);
  81. X    }
  82. X'
  83. X
  84. Xexec 3>&1
  85. X
  86. X/usr/ucb/rsh $hostname $lflag $nflag "${*-:}"'; sh -c "echo $?0 $status >&2"' \
  87. X    2>&1 >&3 | awk "$AWK" >&2
  88. + END-OF-FILE ersh
  89. chmod 'u=rwx,g=rx,o=rx' 'ersh'
  90. set `wc -c 'ersh'`
  91. count=$1
  92. case $count in
  93. 981)    :;;
  94. *)    echo 'Bad character count in ''ersh' >&2
  95.         echo 'Count should be 981' >&2
  96. esac
  97. exit 0
  98. --
  99. "Please DON'T BREAK THE CHAIN!  Terry Wood broke the chain and ended up
  100. writing COBOL PROGRAMS.  Three days later, he found his Blue Star Tatoo
  101. Letter, made 20 copies and mailed them out.  He found a good job writing
  102. compilers."  --  tjw@unix.cis.pitt.edu (Terry J. Wood)
  103.