Operating System - HP-UX
1833883 Members
1860 Online
110063 Solutions
New Discussion

Exit status of remote command

 
SOLVED
Go to solution
Derek Card
Advisor

Exit status of remote command

Hello Experts,

I have a problem getting the exit status of a remsh'ed command
back on my local host. My real problem is that both stdout and stderr are needed and can't be used to echo the status.

I'm stuck. Any ideas?

Thanks,
Derek
1 REPLY 1
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Exit status of remote command

I remember answering one very much like this a while back:

---------------------------
The remsh 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=/var/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_command 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 by your script on the remote host.

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. Since we generate a process id dependent filename on the local host, you don't have to worry about filename collision when multiple instances are running. This method also leaves stderr and stdout for their normal use.

This should do the trick for you,
Clay

If it ain't broke, I can fix that.