maart@cs.vu.nl (Maarten Litmaath) (12/09/89)
Original-posting-by: maart@cs.vu.nl (Maarten Litmaath) Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti) Posting-id: 891208.2057 Posting-number: Volume TEST, Number TEST Archive-name: ersh, rsh front-end which returns the exit status of the remote cmd [This is an experimental alt.sources re-posting from the newsgroup(s) comp.unix.wizards. No attempt has been made to edit, clean, modify, or otherwise change the contents of the original posting, or to contact the author. Please consider cross-posting all sources postings to alt.sources as a matter of course.] [Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti)] In article <256@paralogics.UUCP> shaw@paralogics.UUCP (Guy Shaw) writes: \Rsh does not seem to pass back the return code from the command \executed on another machine. [...] \But, what about the good old Unix(TM)-philosophy tool-building approach? \You know, small general tools that do one job well, and all that. [...] Indeed! ----------8<----------8<----------8<----------8<----------8<---------- #!/bin/sh # @(#)ersh 2.1 89/12/07 Maarten Litmaath # this rsh front-end returns the exit status of the remote command # works OK with sh/csh-compatible shells on the remote side (!) # beware of `funny' chars in `status' when working in sh-compatible shells # if there is no remote command present, /usr/ucb/rlogin is invoked # usage: see rsh(1) hostname= lflag= nflag= case $1 in -l) ;; *) hostname=$1 shift esac case $1 in -l) lflag="-l $2" shift 2 esac case $1 in -n) nflag=-n shift esac case $hostname in '') hostname=$1 shift esac case $# in 0) exec /usr/ucb/rlogin $lflag $hostname esac AWK=' NR > 1 { print prev; prev = $0; prev1 = $1; prev2 = $2; } NR == 1 { prev = $0; prev1 = $1; prev2 = $2; } END { if (prev1 ~ /[0-9]*[0-9]0/) exit(prev1 / 10); if (prev1 == "0") exit(prev2); print prev; exit(1); } ' exec 3>&1 /usr/ucb/rsh $hostname $lflag $nflag "${*-:}"'; sh -c "echo $?0 $status >&2"' \ 2>&1 >&3 | awk "$AWK" >&2 -- `Take John Berryhill: the guy is everywhere! All because one day he typed "rn" instead of [rm]' (Richard Sexton) | maart@cs.vu.nl, uunet!mcsun!botter!maart