Article View: comp.unix.shell
Article #88ersh 3.0 - rsh frontend returning exit status of remote cmd (new)
From: Maarten Litmaath
Date: Tue, 04 Jun 1991 20:35
Date: Tue, 04 Jun 1991 20:35
91 lines
1763 bytes
1763 bytes
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>&-
Technical Details
Message-ID:
<1991Jun04.213511.1536@nat.vu.nl>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
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