getting the return value of a command executed on another host

getting the return value of a command executed on another host

Post by Billy the Ki » Sat, 27 Jan 2001 20:18:24



Folks,
I am doing a shell script in which I have to excute a command on another
host. I can do this by remsh.
So what I do is the typical remsh command
as in remsh hostname command
But what i want is the return value of the command that was executed on the
remot host. When I say echo $? it returns the value of the remsh command
which is successful. I tried this using a command which failed on the remote
host. but still I was gettin $? as 0 since the remsh command itself
succeeded. I am using ksh on HP-UX 10.2

Any pointers??

 
 
 

getting the return value of a command executed on another host

Post by Jean-Philippe Theberg » Sat, 27 Jan 2001 21:47:11



Quote:> Folks,
> I am doing a shell script in which I have to excute a command on another
> host. I can do this by remsh.
> So what I do is the typical remsh command
> as in remsh hostname command
> But what i want is the return value of the command that was executed on the
> remot host. When I say echo $? it returns the value of the remsh command
> which is successful. I tried this using a command which failed on the remote
> host. but still I was gettin $? as 0 since the remsh command itself
> succeeded. I am using ksh on HP-UX 10.2

> Any pointers??

man expect

-jp

 
 
 

getting the return value of a command executed on another host

Post by Michael Wa » Sat, 27 Jan 2001 22:40:50




Quote:>Folks,
>I am doing a shell script in which I have to excute a command on another
>host. I can do this by remsh.
>So what I do is the typical remsh command
>as in remsh hostname command
>But what i want is the return value of the command that was executed on the
>remot host. When I say echo $? it returns the value of the remsh command
>which is successful. I tried this using a command which failed on the remote
>host. but still I was gettin $? as 0 since the remsh command itself
>succeeded. I am using ksh on HP-UX 10.2

There are smart solutions, there are reliable solutions.

Here are reliable solutions:

rsh remote 'command; echo $?'
or variations of this.

Emailed and posted.

 
 
 

getting the return value of a command executed on another host

Post by David Hasset » Sun, 28 Jan 2001 01:01:49





> >Folks,
> >I am doing a shell script in which I have to excute a command on
> >another host. I can do this by remsh.
> >So what I do is the typical remsh command
> >as in remsh hostname command
> >But what i want is the return value of the command that was executed
> >on the remot host. When I say echo $? it returns the value of the
> >remsh command which is successful. I tried this using a command which
> >failed on the remote host. but still I was gettin $? as 0 since the
> >remsh command itself succeeded. I am using ksh on HP-UX 10.2

> There are smart solutions, there are reliable solutions.

> Here are reliable solutions:

> rsh remote 'command; echo $?'
> or variations of this.

Not very reliable if the default shell is a csh. Try this perhaps:

  code=`rsh remote '/bin/sh -c "command; echo $?"'`
  echo $code

Cheers,

Dave. :-)

 
 
 

getting the return value of a command executed on another host

Post by Nate Eldredg » Sun, 28 Jan 2001 01:32:47



Quote:> Folks,
> I am doing a shell script in which I have to excute a command on another
> host. I can do this by remsh.
> So what I do is the typical remsh command
> as in remsh hostname command
> But what i want is the return value of the command that was executed on the
> remot host. When I say echo $? it returns the value of the remsh command
> which is successful. I tried this using a command which failed on the remote
> host. but still I was gettin $? as 0 since the remsh command itself
> succeeded. I am using ksh on HP-UX 10.2

> Any pointers??

Add "echo $?" to your remote command, and then parse it out afterwards?

--

Nate Eldredge

 
 
 

getting the return value of a command executed on another host

Post by mjnem.. » Sun, 28 Jan 2001 02:37:53


searcg the net for a script called ersh, also i've posted  about
this in this here. So you can seach for that thread.



Quote:> Folks,
> I am doing a shell script in which I have to excute a command on
another
> host. I can do this by remsh.
> So what I do is the typical remsh command
> as in remsh hostname command
> But what i want is the return value of the command that was executed
on the
> remot host. When I say echo $? it returns the value of the remsh
command
> which is successful. I tried this using a command which failed on the
remote
> host. but still I was gettin $? as 0 since the remsh command itself
> succeeded. I am using ksh on HP-UX 10.2

> Any pointers??

Sent via Deja.com
http://www.deja.com/
 
 
 

getting the return value of a command executed on another host

Post by kevin_coll.. » Sun, 28 Jan 2001 03:18:11


Its a great solution, assuming that your command has no output - which
means its not a great solution!

I would recommend using ssh - it seems to return the appropriate return
code.

Kevin






> > >Folks,
> > >I am doing a shell script in which I have to excute a command on
> > >another host. I can do this by remsh.
> > >So what I do is the typical remsh command
> > >as in remsh hostname command
> > >But what i want is the return value of the command that was
executed
> > >on the remot host. When I say echo $? it returns the value of the
> > >remsh command which is successful. I tried this using a command
which
> > >failed on the remote host. but still I was gettin $? as 0 since the
> > >remsh command itself succeeded. I am using ksh on HP-UX 10.2

> > There are smart solutions, there are reliable solutions.

> > Here are reliable solutions:

> > rsh remote 'command; echo $?'
> > or variations of this.

> Not very reliable if the default shell is a csh. Try this perhaps:

>   code=`rsh remote '/bin/sh -c "command; echo $?"'`
>   echo $code

> Cheers,

> Dave. :-)

Sent via Deja.com
http://www.deja.com/
 
 
 

getting the return value of a command executed on another host

Post by Nick Hounsom » Tue, 30 Jan 2001 18:48:39




> > Folks,
> > I am doing a shell script in which I have to excute a command on another
> > host. I can do this by remsh.
> > So what I do is the typical remsh command
> > as in remsh hostname command
> > But what i want is the return value of the command that was executed on the
> > remot host. When I say echo $? it returns the value of the remsh command
> > which is successful. I tried this using a command which failed on the remote
> > host. but still I was gettin $? as 0 since the remsh command itself
> > succeeded. I am using ksh on HP-UX 10.2

> > Any pointers??

> Add "echo $?" to your remote command, and then parse it out afterwards?

Or better yet use something like
echo "THERESULTIS $?"
To be sure to be able to pick it out from any output.

- Show quoted text -

> --

> Nate Eldredge