ersh does (was: rsh does not pass back return code)

Maarten Litmaath maart at cs.vu.nl
Fri Dec 8 10:54:06 AEST 1989


In article <256 at paralogics.UUCP> shaw at 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 at cs.vu.nl, uunet!mcsun!botter!maart



More information about the Comp.unix.wizards mailing list