Operating System - HP-UX
1753539 Members
5484 Online
108795 Solutions
New Discussion юеВ

Test return value from remsh'd script

 
SOLVED
Go to solution
Hamish Tunley
New Member

Test return value from remsh'd script

We have various scripts that need to remsh to another server to run a seperate script. These processes are automated, so we need to test that the remote script has successfuly completed. Either by a return code of '0' or something. If you ran an echo $? after the remsh command it is only going to test that the actual 'remsh' command completed. What is the easiest and most robust way to test such a thing? Logging all the output from the remote script, and then grep for some value on that server?

Thanks

Hamish
Has anyone experienced the same queries
6 REPLIES 6
harry d brown jr
Honored Contributor

Re: Test return value from remsh'd script

Have your script that's running on the remote host log the errors and return values you want, then rcp them back after you remsh, then grep out the values you need.

live free or die
harry
Live Free or Die
Jeff Machols
Esteemed Contributor

Re: Test return value from remsh'd script

Hamish

It depends what your remote script does. If it does not have anything doing to standard out, you can do something like this

VAL=`remsh node script.sh`

#####
Script.sh
code
...
echo $RETRUN_VAL

or you could do something like this

remsh node script.sh
VAL=`remsh cat ret_file`

#####
Script.sh
code
...
echo $RETURN_VAL > ret_file
A. Clay Stephenson
Acclaimed Contributor

Re: Test return value from remsh'd script

Hi Hamish:

Yes that question has come up many times. I will simply duplicate one of my earlier posts.
NOTE: This is the most general solution to the problem when you also need STDOUT and STDERR from your remsh'ed process. i.e. This method works in all cases.

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.

You can serach the Forums for remsh and status for other methods.

Regards, Clay
If it ain't broke, I can fix that.
JACQUET
Frequent Advisor

Re: Test return value from remsh'd script

Hi,

Here is an example i use (in a Ksh Shell). The Idea: Put the value of the return remsh in a variable, and test that variable afterwards.

CMD_RELEASE_DSK="/usr/bin/remsh $SERVEUR_CIBLE -l root -n '${SHELL_CONTROL_SERVEUR_CIBLE} RELEASE ; echo $?'"
RESULT=`eval ${CMD_RELEASE_DSK}`
if [ $RESULT -eq 0 ] ; then
echo "Ok"
else
echo "Ko"
fi

It may help

regards

PJA.
PJA
Robin Wakefield
Honored Contributor
Solution

Re: Test return value from remsh'd script

Hi Hamish,

For a one-off return code check:

remsh host "your_script;echo $?" > /tmp/returncode

Then grep /tmp/returncode locally.

Rgds, Robin.
marc seguin
Regular Advisor

Re: Test return value from remsh'd script

Hi,

Robin's solution needs a modification :

remsh host "your_script;echo \$?" > /tmp/returncode

or use simple quotes instead.