Operating System - HP-UX
1834142 Members
2271 Online
110064 Solutions
New Discussion

Re: Return code for remote shell

 
SOLVED
Go to solution
Ila Nigam
Occasional Contributor

Return code for remote shell

Any idea how to get the exit status/return code for any remote shell command? Always get 0 exit status even if it fails.

Thanks
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Return code for remote shell

Hi:

You can (should) write the return code of the process you want to interrogate (after the fact) into a file, and then examine that file for the value the process returned.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Return code for remote shell

This thread pretty much covers all the bases.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x7e2d8ffa98a2d5118ff10090279cd0f9,00.html
If it ain't broke, I can fix that.
Chris Vail
Honored Contributor

Re: Return code for remote shell

Best deal of all: stop using remote shell altogether. Use secure shell instead. Secure shell will return the exit status of whatever it ran on the remote host:
# ssh REMHOST "uname -n"
# REMHOST
# echo "$?"
# 0
# ssh REMHOST "uname -b"
uname: illegal option -- b
usage: uname [-amnrsvil] [-S nodename]
# echo "$?"
1
#

You can get secure shell from softward.hp.com or a lot of other places. Attached is the document I seem to be posting at least once day that describes how to install it and use it so that you won't be challenged for passwords.
Bill Hassell
Honored Contributor

Re: Return code for remote shell

The return code for remsh is working correctly: it returns 0 if the remsh command can connect to the remote system and send the rest of the command line to the remote system. There is only one return code to indicate remsh's success, not the command(s) sent to the remote system. remsh will return a non-zero value if the HOSTNAME is not valid or refuses to allow a login. Command results must be returned through a separator mechanism as mentioned in the above comments.


Bill Hassell, sysadmin
Brian Crabtree
Honored Contributor

Re: Return code for remote shell

You could also do something like:

REMSTAT=`remsh remhost 'cmd 1> /dev/null 2>&1 ;
if [ $? -eq 1 ]; then
echo 1
else
echo 0
fi'`

Thanks,

Brian