ersh - rsh frontend hack returning exit status of remote cmd

ersh - rsh frontend hack returning exit status of remote cmd

Post by Maarten Litmaa » Thu, 31 Jan 1991 09:26:48



#!/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.

 
 
 

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. Problems with TFT monitor

3. capturing exit status for cmd when invoking 'xterm -e cmd'

4. Sendmail Question

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

6. Linux / Windows

7. rsh status using ersh

8. help with xdm and wmaker (netBSD 1.4.1, sparc)

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

10. ?ksh: exit status of 1st cmd in pipe?

11. exit status using rsh

12. rsh exit status

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