Xref: utzoo comp.unix.shell:2338 comp.unix.programmer:1994 alt.sources:3851 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!hp4nl!star.cs.vu.nl!nat.vu.nl!maart From: maart@nat.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.shell,comp.unix.programmer,alt.sources Subject: ersh 3.0 - rsh frontend returning exit status of remote cmd (new) Message-ID: <1991Jun04.213511.1536@nat.vu.nl> Date: 4 Jun 91 20:35:11 GMT Followup-To: comp.unix.programmer Organization: Dept. of Physics, Vrije University, Amsterdam, The Netherlands Lines: 91 This version is more bulletproof. --------------------cut here-------------------- #!/bin/sh # @(#)ersh 3.0 91/06/04 Maarten Litmaath # This rsh front-end returns the exit status of the remote command, # or 99 if the connection is broken prematurely. # It works OK with sh/csh-compatible shells on the remote (!) side. # If there is no remote command present, rlogin is invoked, which # need not return a meaningful exit status. # Usage: see rsh(1). RSH=/usr/ucb/rsh RLOGIN=/usr/ucb/rlogin hostname= lflag= nflag= user= case $1 in -l) ;; *) hostname=${1?'hostname expected'} shift esac case $1 in -l) lflag=-l shift user=${1?'username expected after -l flag'} shift esac case $1 in -n) nflag=-n shift esac case $hostname in '') hostname=${1?'hostname expected'} shift esac case $# in 0) exec $RLOGIN $lflag $user "$hostname" esac id=ersh.$$.`date | awk '{ print $4; }'` hangup=99 AWK=' prprev == 1 { print prev0; prprev = 0; } $1 == "'$id'" { prev0 = $0; prev2 = $2; prev3 = $3; prprev = 1; next; } { print; } END { if (prprev == 0) { exit('$hangup'); } if (prev2 ~ /^[0-9]+0$/) { exit(prev2 / 10); } if (prev2 ~ /^0$/ && prev3 ~ /^[0-9]+$/) { exit(prev3); } exit('$hangup'); } ' exec 3>&1 cmd="( ${*-:} ); exec sh -c 'echo $id "'"$0 $1" >&2'\'' $?0 "$status"' $RSH "$hostname" $lflag $user $nflag "$cmd" 2>&1 >&3 3>&- | awk "$AWK" >&2 3>&-