1832549 Members
6034 Online
110043 Solutions
New Discussion

read exit code

 
Adam_116
Occasional Advisor

read exit code

Hi,
i want read exit code for command "remsh ecsmgr -i 3 -info".
Next I have try typing "remsh echo $?" but result is always "0".
Please help me.
Thanks
9 REPLIES 9
Karthik S S
Honored Contributor

Re: read exit code

Try doing a,

"remsh ecsmgr -i 3 -info; echo $?"

-Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Mark Grant
Honored Contributor

Re: read exit code

You need to do it like this!

EXITCODE=`remsh 'echo $?'`

However, this will be a problem if you have more output than just the exit code.
Never preceed any demonstration with anything more predictive than "watch this"
Steven E. Protter
Exalted Contributor

Re: read exit code

What you need to do is.

remesh scriptname

The script looks like this:

escmgr -i 3 -info
rc=$?
if [ $rc -ne 0 ]
then
echo "Bad Script $rc"
else
echo "Good Script"
fi

return $rc

This will at least be able to act on the error code and might return the code you want(probably not)

The 0 you are getting back is for the remesh command. That has been successful.

Try remesh for a server that does not exist. That will give you a non-zero error code.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Adam_116
Occasional Advisor

Re: read exit code

Very thanks at all!!!

Finally solution is:

remsh nmcmds11 '/opt/OV/bin/ecsmgr -i 3 -info >/dev/null 2>&1 ; remsh nmcmds11 echo $?'

Hi.
Jeroen Peereboom
Honored Contributor

Re: read exit code

Adam,

Did you test your solution thoroughly? I assume there's a typo in it with you apostrophes and that you are issuing 2 remsh commands.

I don't see why the second remsh will report the first's exit code. There is no relationship between these two commands, from the nmcmds11's point of view.

What the other replies try to tell you is that you must distinguish between the exit code of the remsh itself, and the exit code of the command executed on the remote server.
That's why they suggest to generate some output that can be interpreted on the machine that starts the remsh commands.

JP.
Elmar P. Kolkman
Honored Contributor

Re: read exit code

I think Jeroen is right: there is no relationship between the echo and the first remote shell commando. What you should do is combine them.

For instance: remsh 'ecsmgr -i 3 -info ; echo $?'

Every problem has at least one solution. Only some solutions are harder to find.
Adam_116
Occasional Advisor

Re: read exit code

Hi,
Jeroen is right and if i type 2 remsh consecutive result exit code is not correct.
Just solved problem whith this strings:
$ECS_STATUS = `remsh $SERVER '/opt/OV/bin/ecsmgr -i 3 -info >/dev/null 2>&1 ; echo \$?'`;

The symbol "\" before "$?" does not allow the program to interpret "$?" like local variable but like remote variable.

Bye
Paula J Frazer-Campbell
Honored Contributor

Re: read exit code

Adam

Please assign point to answers if they were helpful.

http://forums1.itrc.hp.com/service/forums/helptips.do?#22

Paula
If you can spell SysAdmin then you is one - anon
Chris Vail
Honored Contributor

Re: read exit code

This is another reason to install and use secure shell rather than remsh. Secure shell returns the exit code properly from the remotely executed code. This is handy for testing the outcome of commands without going through a lot gyrations to capture it.
Secure shell is free. Install it as you do any depot. I've attached my usual file that describes how to configure it so that it doesn't challenge for passwords. Here is an example:

# ssh DESTHOST "ls -l /etc/hots"
# echo "$?"
2
#
#ssh DESTHOST "ls -l /etc/hosts"
#echo "$?"
0
#

Good luck
Chris