rsh exit status using ersh

rsh exit status using ersh

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



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;

Quote:}

NR == 1 {
   prev = $0;
   prev1 = $1;
   prev2 = $2;
Quote:}

END {
   if (prev1 ~ /[0-9]*[0-9]0/)
   exit(prev1 / 10);
   if (prev1 == "0")
   exit(prev2);
   print prev;
   exit(1);
Quote:}

'

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"

Quote:>&2 3>&-

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

rsh exit status using ersh

Post by Donn Ca » Sat, 31 Jul 1999 04:00:00


| 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.

I am sorry to say, the program you attached didn't make it.  It was
pretty badly garbled in transmission.

Here's one tip - it looked to me like you may have tried to integrate
your script into the ersh script, and that wouldn't be a good idea.
It's rather complicated even if you understand all the details and
what it's trying to do, but you don't have to look inside, just use
use it IN PLACE of rsh.  

Well, you do have to look inside if you need to replace /usr/ucb/rsh
with /usr/bin/remsh or something like that, but just do what you need
to make it work.  Try it with a simple command, like
"./ersh remote-host echo hi"

exec 3>&1 opens a new unit 3 on the old unit 1 output stream.  Then
in the rsh|awk pipe, where unit 1 is now the pipe, he restores the old
unit 1 with >&3, after adding unit 2 to the pipe with 2>&1.  In other
words, he's juggling file descriptors to make unit 2 go through the
pipe instead of unit 1.

A lot of the complexity is there because the remote shell might be csh
or tcsh.  We'll never be finished paying the price for that bad idea.

        Donn Cave, University Computing Services, University of Washington


 
 
 

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

#!/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" >&2 3>&-
--
Temporary files like /tmp/sh$$ are an abomination.

2. Unable to Change Monitor's Resolution

3. rsh status using ersh

4. Off-topic ?

5. exit status using rsh

6. Opinions on Applixware

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

8. Security Policies

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

10. rsh exit status

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

12. exit status of rsh

13. Exit status in trapped exit function