rsh exit status

rsh exit status

Post by csupin.. » Sat, 17 Jul 1999 04:00:00



Help -- my understanding of the rsh command is that the exit status
only reflects the success/failure of the rsh command itself and has
nothing to do with the command you are trying to run.  Is there any way
to have the rsh command exit with the status of the command that was
issued?

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 
 
 

rsh exit status

Post by Ken Pizzi » Sat, 17 Jul 1999 04:00:00



>Help -- my understanding of the rsh command is that the exit status
>only reflects the success/failure of the rsh command itself and has
>nothing to do with the command you are trying to run.  Is there any way
>to have the rsh command exit with the status of the command that was
>issued?

There are various hacks floating about which do this (check DejaNews
for this newsgroup and/or comp.unix.shell; in the last couple of
weeks a script to do this was posted).  The basic concept is to:
   rsh remotehost "command; echo $?"
and then to examine the last line of rsh's output.

Another option is to use a different remote-execution tool,
such as ssh, which is better designed in this respect.

                --Ken Pizzini

 
 
 

1. rsh exit status using ersh

I recently tried to use the "ersh" script created by Maarten Litmaath to
retrieve the status of the remote command rather than the rsh command.
However, it always returned a status of 1 no matter what I tried.  I am
a relative neophite when it comes to complex UNIX commands and awk so
could someone explain what the it is doing (I'm OK until the "exec3>&1"
line and I understand the "rsh" command until it starts echoing and
redirecting things) or what I'm doing wrong. I have attached the
program.

Thanks

ersh expects to find commands in their original Berkeley names and
places, so you will have to edit it a bit to accommodate your platform.

Donn Cave, University Computing Services, University of Washington

-----------------------------
#!/bin/sh

# This rsh front-end returns the exit status of the remote command. # It
works OK with sh/csh-compatible shells on the remote (!) side. # If
there is no remote command present,
/usr/ucb/rlogin is invoked. # Usage: see rsh(1).

# unset hostname lflag nflag user

case "$1" in
      -l)
;;
      *)
hostname=$1
shift
esac

case "$1" in
      -l)
lflag=-l
user=$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 ${user+"$user"} "$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 ${user+"$user"} $nflag \ "(${*-:}); sh
-c '"'echo "$0 $1" >&2'\'' $?0 "$status"' \ 2>&1 >&3 3>&- | awk "$AWK"

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

2. -= Setting up an SLIP connection =-

3. How to get the exit status of a remote command executed via rsh

4. Top 10 posters comp.unix.questions

5. ersh - rsh frontend hack returning exit status of remote cmd

6. Q on command

7. exit status using rsh

8. Virtual disks on Altos/SCO 4.2

9. how to force rsh to exit with status of remote command

10. Getting exit status for a command completed by rsh.

11. exit status of rsh

12. Exit status in trapped exit function

13. rsh - getting the status of an rsh'd command