[comp.unix.questions] Help with RSH error status return

sscott@camdev.UUCP (Steve Scott) (07/13/89)

If this is too simple (or I should've done a better job
of RTFM) please e-mail responses.  I've got a pretty thick
skin

Anyway,

Assume that I have a simple Bourne shell script (called
dumb_script) on machine B which has one line:

           exit 3

Immediately after running this, echo $? of course says 3

No problem.


But, now assume that another host machine (say A) uses

           rsh B dumb_script

An echo $? after this script always returns a 0 (assuming
that rsh was able to complete properly).  I understand
all of this.  But what I WANT to do is to have 

           rsh B dumb_script

have a return error status equal to the return error status
of the program which ran on machine B (that is, 3 in this
case)

Any hints/tips/ideas/pointers to the proper man pages/etc?




-- 
Steve Scott            UUCP: {killer|texbell}!camdev!sscott
Motorola, Inc.         Telephone : 1-817-232-6317

chris@mimsy.UUCP (Chris Torek) (07/14/89)

In article <201@camdev.UUCP> sscott@camdev.UUCP (Steve Scott) writes
[nb: this is my own summary]
	sh -c 'exit 3'
	echo $?
produces 3, but
	rsh otherhost 'exit 3'
	echo $?
produces 0.  The question is how to get at the `exit 3' that happens
on machine otherhost.

>Any hints/tips/ideas/pointers to the proper man pages/etc?

rsh (4BSD rsh, remote shell, not the `restricted' shell) will not
import the exit status of a remote command.  This is understandable
(how will you tell `remote process exit status is X' from `local
rsh exit status is X'?) but can be extremely annoying.

The only solution is to run a command on the remote machine that
runs the command that you want run, then passes back that command's
exit status.  E.g., instead of

	rsh otherhost mycmd

you need something like

	rsh otherhost myfrontend

where `myfrontend' is a program like this shell script:

	#! /bin/sh
	mycmd
	echo $?

This is not completely reliable; you have to write a more complex
protocol (such as that used by rcp) to tell whether things went well or
ill, and even that is not foolproof (as rcp sometimes demonstrates).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

guy@auspex.auspex.com (Guy Harris) (07/15/89)

 >But what I WANT to do is to have 
 >
 >           rsh B dumb_script
 >
 >have a return error status equal to the return error status
 >of the program which ran on machine B (that is, 3 in this
 >case)
 >
 >Any hints/tips/ideas/pointers to the proper man pages/etc?

The only pointer is to the code, which I just checked; there's no way to
do it.  "rsh", at least in the 4.3BSD and 4.3-tahoe versions (from which
most if not all other versions are derived) always exits with an exit
status of 0, 1, or 2; it pays no attention to the exit status of the
remote command (it may not even be able to *get* that exit status; a
quick check of the RSHD(8C) man page doesn't indicate that the daemon
even provides that to "rsh").

pvo@uther.CS.ORST.EDU (Paul V O'Neill) (07/15/89)

In article <201@camdev.UUCP> sscott@camdev.UUCP (Steve Scott) writes:
>
>           But what I WANT to do is to have 
>
>           rsh B dumb_script
>
>have a return error status equal to the return error status
>of the program which ran on machine B  ........

Welllll..... this isn't exactly the answer you requested, BUT, since noone
can come up with how to do it w/ sh, here's how to do it w/ csh.


#!/bin/csh
cd /your/favorite/directory
if ( -f testlogin ) \rm testlogin
if ( -f teststatus ) \rm teststatus

(rsh B dumb_script >& teststatus) >& testlogin
............

You may now test the file teststatus for any output from dumb_script
and test the file testlogin for any login error messages.  Of course, if
dumb_script is a csh script whose last line is "echo $status", well,
there you are.



Paul O'Neill                 pvo@oce.orst.edu
Coastal Imaging Lab
OSU--Oceanography
Corvallis, OR  97331         503-737-3251