exit status using rsh

exit status using rsh

Post by Morten Wendell Pederse » Sat, 24 Jan 1998 04:00:00



Hi

Is it possible to get exit status of a program started with rsh, so I can use
it in a shell script (Bourne).
The problem I have is when pipe my stuff from one command on one machine
and want a while loop to terminate when the remote end fails, my rsh
returns that everything was okay.... forever.... (and as it is the last command
it takes precendence over the first one):

while  (  local_command| rsh remote_host remote_command )
.....Do Something

A workaround could be to swap the remote and local entry, which will
work in some sitaution (when it does not matter which machine is used for
local and remote operation),

while  (  rsh remote_host original_local_command| original_remote_command )
.....Do Something

however does anyone know a way to get original loop to terminate
corrrectly, I would be happy

-Morten

--

------------------------------------------------------------------------
Be cautious in your daily affairs.
------------------------------------------------------------------------

 
 
 

exit status using rsh

Post by Donn Ca » Sat, 24 Jan 1998 04:00:00



| Is it possible to get exit status of a program started with rsh, so I can use
| it in a shell script (Bourne).

Yes, it is possible.  The exit status, on the remote end, is $?, assuming
Bourne shell and family;  just send that back as output.  The procedure
is presumably explained in detail in the c.u.s FAQ, after a script called
"ersh" contributed years ago by one Maarten Litmaath (hope I spelled that
right.)

...
| while  (  local_command| rsh remote_host remote_command )
| .....Do Something

Note that rsh is also capable of wasting your input stream, that is,
whether the remote command actually consumes input or not, rsh may
take a buffer full just on principle.  This has caused me some
embarrassment.  It can be avoided with the "-n" flag, of course
only if the remote command doesn't want to read input.  In the
special case, like a shell "read" command, where only a limited
amount of input is consumed, I don't think there's any general solution.

        Donn Cave, University Computing Services, University of Washington


 
 
 

exit status using rsh

Post by Gerard Talma » Sat, 24 Jan 1998 04:00:00


You can do something along these lines:

while  (  test "`local_command| rsh remote_host ( remote_command ; echo
$? )`" = "0" )
.....Do Something

I couldn't test it, but I did something like this a while ago,
and it worked. It kind of a messy way though.

Gerard Talman


> Hi

> Is it possible to get exit status of a program started with rsh, so I can use
> it in a shell script (Bourne).
> The problem I have is when pipe my stuff from one command on one machine
> and want a while loop to terminate when the remote end fails, my rsh
> returns that everything was okay.... forever.... (and as it is the last command
> it takes precendence over the first one):

> while  (  local_command| rsh remote_host remote_command )
> .....Do Something

> A workaround could be to swap the remote and local entry, which will
> work in some sitaution (when it does not matter which machine is used for
> local and remote operation),

> while  (  rsh remote_host original_local_command| original_remote_command )
> .....Do Something

> however does anyone know a way to get original loop to terminate
> corrrectly, I would be happy

> -Morten

> --

> ------------------------------------------------------------------------
> Be cautious in your daily affairs.
> ------------------------------------------------------------------------

 
 
 

exit status using rsh

Post by Icarus Sparr » Sat, 24 Jan 1998 04:00:00



Quote:>Is it possible to get exit status of a program started with rsh, so I can use
>it in a shell script (Bourne).

Yes. If you read the FAQ for this newsgroup you will see question 3.11 is
'How do I check the exit status of a remote command executed via "rsh"', which
is almost word for word your question. It even supplies an answer!
 
 
 

exit status using rsh

Post by James R. Mart » Sun, 25 Jan 1998 04:00:00



: Hi
: Is it possible to get exit status of a program started with rsh, so I can use
: it in a shell script (Bourne).
: The problem I have is when pipe my stuff from one command on one machine
: and want a while loop to terminate when the remote end fails, my rsh
: returns that everything was okay.... forever.... (and as it is the last command
: it takes precendence over the first one):

This is answered in the FAQ.

-james

 
 
 

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. error when installing disks

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

4. Yet another DHCP/sendmail question

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

6. Sun BluePrints Online: Tuning Oracle, Intro to the ClusterGrid, and more

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

8. TCP/UDP checksum error with IP masquerading

9. rsh exit status

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