Operating System - HP-UX
1834936 Members
2194 Online
110071 Solutions
New Discussion

Re: exit values when remsh

 
thewho?
Frequent Advisor

exit values when remsh

Hello,
HPUX 11.0 64-bit, N4000
I'm writing a script that will execute scripts in a remote server using remsh, for example:

remsh myhost -n myscript.sh myfile 2>rmcmd.err \; echo $?

I'd like to know if there is a way to get the exit value of myscript.sh.
If I run myscript.sh locally in myhost, I get $? set to the correct exit value, but when I ran the above command on theotherhost I always get 0 no matter what.
Thanks in Advance,
Luis
We'll get through this together.
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor

Re: exit values when remsh

Hi Luis:
You have found a remsh and remshd feature. The exit code of 0 only means that the script was able to be launched. The exit status of the remote command is not returned. There is a workaround I have used for a long time.

REM_ERR_FILE=/tmp/x${$}.err
remsh remote_host my_command $REM_ERR_FILE
LOCAL_STAT=$?

$LOCAL_STAT only tells us about the success of remsh itself

Now my_coomand on the remote host can get the
value of $REM_ERR_FILE; any status values you are interested in can be written to that file.

When the remsh command finishes you can then
REM_STAT=`remsh remote_host cat ${REM_ERR_FILE}`
to capture the remote commands status. (You should then issue a final remsh to remove the $REM_ERR_FILE.)

It's a little complicated but it does work.

Hopes this gets you started, Clay


Now imagine that
If it ain't broke, I can fix that.
Wieslaw Krajewski
Honored Contributor

Re: exit values when remsh

Hi,

I've tried to do what you want in a direct way as
follows:

remsh myhost 'myscript.sh myfile 2>rmcmd.err ;echo $?'

Remember, sorrounding remote command by ' ' is important.

Rgds.
Permanent training makes master