Xref: utzoo comp.unix.shell:937 alt.sources:2621 Path: utzoo!utgpu!cs.utexas.edu!sdd.hp.com!usc!apple!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.shell,alt.sources Subject: Re: returning values from an rsh. Message-ID: <8318@star.cs.vu.nl> Date: 21 Nov 90 16:13:46 GMT References: Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Followup-To: comp.unix.shell Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 96 In article , fridman@cs-sun-aa.cs (fridman) writes: ) )I need a way for an rsh to return the status of the last )command that it executed on the remote machine. : This is a shar archive. Extract with sh, not csh. : This archive ends with exit, so do not worry about trailing junk. : --------------------------- cut here -------------------------- PATH=/bin:/usr/bin:/usr/ucb echo Extracting 'ersh' sed 's/^X//' > 'ersh' << '+ END-OF-FILE ''ersh' X#!/bin/sh X# @(#)ersh 2.1 89/12/07 Maarten Litmaath X# this rsh front-end returns the exit status of the remote command X# works OK with sh/csh-compatible shells on the remote side (!) X# beware of `funny' chars in `status' when working in sh-compatible shells X# if there is no remote command present, /usr/ucb/rlogin is invoked X# usage: see rsh(1) X Xhostname= Xlflag= Xnflag= X Xcase $1 in X-l) X ;; X*) X hostname=$1 X shift Xesac X Xcase $1 in X-l) X lflag="-l $2" X shift 2 Xesac X Xcase $1 in X-n) X nflag=-n X shift Xesac X Xcase $hostname in X'') X hostname=$1 X shift Xesac X Xcase $# in X0) X exec /usr/ucb/rlogin $lflag $hostname Xesac X XAWK=' X NR > 1 { X print prev; X prev = $0; X prev1 = $1; X prev2 = $2; X } X NR == 1 { X prev = $0; X prev1 = $1; X prev2 = $2; X } X END { X if (prev1 ~ /[0-9]*[0-9]0/) X exit(prev1 / 10); X if (prev1 == "0") X exit(prev2); X print prev; X exit(1); X } X' X Xexec 3>&1 X X/usr/ucb/rsh $hostname $lflag $nflag "${*-:}"'; sh -c "echo $?0 $status >&2"' \ X 2>&1 >&3 | awk "$AWK" >&2 + END-OF-FILE ersh chmod 'u=rwx,g=rx,o=rx' 'ersh' set `wc -c 'ersh'` count=$1 case $count in 981) :;; *) echo 'Bad character count in ''ersh' >&2 echo 'Count should be 981' >&2 esac exit 0 -- "Please DON'T BREAK THE CHAIN! Terry Wood broke the chain and ended up writing COBOL PROGRAMS. Three days later, he found his Blue Star Tatoo Letter, made 20 copies and mailed them out. He found a good job writing compilers." -- tjw@unix.cis.pitt.edu (Terry J. Wood)