1823219 Members
3745 Online
109648 Solutions
New Discussion юеВ

Re: Doubt in remsh

 
Ramsunder S
Occasional Advisor

Doubt in remsh

Hi,
We are facing a problem in getting the exit status of a script run remotely.
For e.g.,
We have script1 running on server1 that executes script2 on server2 using remsh. "script2" may exit with status codes other than 0. We need script1 to capture that code. Is there any mechanism to do this.
We are working on HP-UX 11i.

The man pages do seem to suggest that it is not possible to get the exit status of a remotely run script. Just wanted to make sure.

Any information in this regard is appreciated.

Regards,
Ram.
3 REPLIES 3
Chris Wilshaw
Honored Contributor

Re: Doubt in remsh

the exit code of 0 is from remsh itself.

What you need to do is display the exit code from the remote command to screen, then process the output locally.

You could set it up as a variable using the following;

export REMOTE_EXIT_CODE=`remsh server2 "script;echo $?"`

You can then use the value of REMOTE_EXIT_CODE in the script on server1 for verification that it has worked.
G. Vrijhoeven
Honored Contributor

Re: Doubt in remsh

Hi Ram,

Since Script2 is on server2 and runs on server2 i would alter that script with one line, echo $? >script2.exit. and alter your remsh command so
EXIT=remsh -n "script2 >>/dev/null ; cat script2.exit"`
if [ $EXIT -ne 0 ]
then
echo ": HELP!!!!"
fi

HTH,

Gideon

PS with ssh you can capture exit status of remote executed commands
Mark Grant
Honored Contributor

Re: Doubt in remsh

There may be a simpler way but this was the first thing that came to mind and it seems to work.

RET=`rsh hostname "false;echo \$?"`
echo $RET

This gives "1" in the above example which is correct. You'll have to do annoying stuff if the command you want to run actually has output.
Never preceed any demonstration with anything more predictive than "watch this"