<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: rsh and return code in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915634#M406887</link>
    <description>I've tried it with both ssh and remsh and it seems to work fine.  Not sure why you always see a 0 result.</description>
    <pubDate>Tue, 02 Aug 2005 14:34:50 GMT</pubDate>
    <dc:creator>Pat Lieberg</dc:creator>
    <dc:date>2005-08-02T14:34:50Z</dc:date>
    <item>
      <title>rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915628#M406881</link>
      <description>Hi everyone,&lt;BR /&gt;&lt;BR /&gt;Someone posted ssh and return code and did not get much replies. I'm looking for rsh and return code when between Servers.&lt;BR /&gt;Does anyone know how to trap rsh return code? For example, on server A, rsh to server B and run command X (which run non-zero on error or when ran directly on Server B). I would like to trap the return code of command X when rshed from Server A. Currently rsh -l username ServerB command &lt;BR /&gt;always return 0&lt;BR /&gt;&lt;BR /&gt;The long way to this would be to trap the return code to a file when running command X on server B, then run a rcp to grab that file from server A. Any ideas?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance for your time.&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Aug 2005 11:53:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915628#M406881</guid>
      <dc:creator>Mike_Ca Li</dc:creator>
      <dc:date>2005-08-02T11:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915629#M406882</link>
      <description>You could use the conditional || on the command line to return $? if the command fails.&lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;rsh remotehost -n cat /tmp/file || echo $?&lt;BR /&gt;&lt;BR /&gt;Shouldn't be too hard to capture the code that is returned.</description>
      <pubDate>Tue, 02 Aug 2005 12:43:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915629#M406882</guid>
      <dc:creator>Pat Lieberg</dc:creator>
      <dc:date>2005-08-02T12:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915630#M406883</link>
      <description>Do it as follows.&lt;BR /&gt;&lt;BR /&gt;rsh remotehost 'cat /tmp/file;echo $?'&lt;BR /&gt;&lt;BR /&gt;Anil</description>
      <pubDate>Tue, 02 Aug 2005 13:16:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915630#M406883</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2005-08-02T13:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915631#M406884</link>
      <description>We have this scenerio:&lt;BR /&gt;"rsh -l username ServerB /home/username/bin/programX"; echo$?&lt;BR /&gt;It will always return 0 because the rsh will run successfully. &lt;BR /&gt;&lt;BR /&gt;in programX, I have codes to check for running of a backup program on ServerB. If backup is success, 0 is returned, but if failure, 99 is returned. If programX is ran on ServerB when backup failed, echo$? gives 99, but when ran with rsh, echo$? gives 0. How does return code is propagated via rsh ?&lt;BR /&gt;I tried with -n still did not work. Please advise. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Aug 2005 13:50:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915631#M406884</guid>
      <dc:creator>Mike_Ca Li</dc:creator>
      <dc:date>2005-08-02T13:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915632#M406885</link>
      <description>You need to include the ;echo $? inside the quotes of the command passed to rsh as in RAC's example above.  Otherwise you are getting the return code of the rsh and not the return code of the remote program.</description>
      <pubDate>Tue, 02 Aug 2005 13:56:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915632#M406885</guid>
      <dc:creator>Pat Lieberg</dc:creator>
      <dc:date>2005-08-02T13:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915633#M406886</link>
      <description>Hi Pat:&lt;BR /&gt;I don't think that double quotes are the issue. &lt;BR /&gt;rsh -l username ServerB /home/username/programX; echo $?&lt;BR /&gt;returns 0</description>
      <pubDate>Tue, 02 Aug 2005 14:20:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915633#M406886</guid>
      <dc:creator>Mike_Ca Li</dc:creator>
      <dc:date>2005-08-02T14:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915634#M406887</link>
      <description>I've tried it with both ssh and remsh and it seems to work fine.  Not sure why you always see a 0 result.</description>
      <pubDate>Tue, 02 Aug 2005 14:34:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915634#M406887</guid>
      <dc:creator>Pat Lieberg</dc:creator>
      <dc:date>2005-08-02T14:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915635#M406888</link>
      <description>On second thought, there's only two things running here, your rsh and the remote command.  The zero result must be coming from the rsh if you know the remote command is failing.  That means the shell is running your echo $? on the local system and not remotely.&lt;BR /&gt;&lt;BR /&gt;Enclosing the command in single quotes will guarantee the echo is run remotely.&lt;BR /&gt;&lt;BR /&gt;If I do:&lt;BR /&gt;&lt;BR /&gt;remsh hostname 'cat blah';echo $?&lt;BR /&gt;&lt;BR /&gt;the result is:&lt;BR /&gt;cat: Cannot open blah: No such file or directory&lt;BR /&gt;0&lt;BR /&gt;&lt;BR /&gt;However, if I do:&lt;BR /&gt;&lt;BR /&gt;remsh hostname 'cat blah;echo $?'&lt;BR /&gt;&lt;BR /&gt;the result is:&lt;BR /&gt;&lt;BR /&gt;cat: Cannot open blah: No such file or directory&lt;BR /&gt;2&lt;BR /&gt;&lt;BR /&gt;Sorry to keep on the quotes but I can't think of what else would cause your return code to always be 0.</description>
      <pubDate>Tue, 02 Aug 2005 14:42:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915635#M406888</guid>
      <dc:creator>Pat Lieberg</dc:creator>
      <dc:date>2005-08-02T14:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915636#M406889</link>
      <description>Hi Pat:&lt;BR /&gt;&lt;BR /&gt;You got something there with the single quote:&lt;BR /&gt;remsh hostname 'cat blah;echo $?'&lt;BR /&gt;&lt;BR /&gt;the result is:&lt;BR /&gt;&lt;BR /&gt;cat: Cannot open blah: No such file or directory&lt;BR /&gt;2&lt;BR /&gt;&lt;BR /&gt;But how to do something like below:&lt;BR /&gt;remsh hostname 'cat blah; result=$?;export result'&lt;BR /&gt;if [ $result -eq 2 ]&lt;BR /&gt;then&lt;BR /&gt;pageout&lt;BR /&gt;fi&lt;BR /&gt;Currently [ $result -eq 2 ] is failing because the result variable is not being returned to the shell. Any more insights? I'll assign points. Thank you. &lt;BR /&gt;</description>
      <pubDate>Tue, 02 Aug 2005 15:19:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915636#M406889</guid>
      <dc:creator>Mike_Ca Li</dc:creator>
      <dc:date>2005-08-02T15:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915637#M406890</link>
      <description>Your best bet is to capture the result of the command to a variable:&lt;BR /&gt;&lt;BR /&gt;result=$(remsh hostname 'cat blah 2&amp;gt;/dev/null; result=$?')&lt;BR /&gt;if [ $result -eq 2 ]&lt;BR /&gt;then&lt;BR /&gt;pageout&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;The 2&amp;gt;/dev/null makes it so any error messages are not captured and the $result variable will get just the return code number.</description>
      <pubDate>Wed, 03 Aug 2005 07:25:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915637#M406890</guid>
      <dc:creator>Pat Lieberg</dc:creator>
      <dc:date>2005-08-03T07:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915638#M406891</link>
      <description>If one tests this following, result is not set to anything. &lt;BR /&gt;&lt;BR /&gt;result=$(remsh hostname 'cat /tmp/blah 2&amp;gt;/dev/null; result=$?')&lt;BR /&gt;if [ $result -eq 2 ]&lt;BR /&gt;then&lt;BR /&gt;pageout&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Aug 2005 08:35:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915638#M406891</guid>
      <dc:creator>Mike_Ca Li</dc:creator>
      <dc:date>2005-08-03T08:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915639#M406892</link>
      <description>You need to return the result from the command; any assignment you do will be done remotely.&lt;BR /&gt;&lt;BR /&gt;Something like this should work:&lt;BR /&gt;&lt;BR /&gt;result=$(remsh hostname 'cat /tmp/blah 2&amp;gt;/dev/null; echo $?')&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Aug 2005 08:44:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915639#M406892</guid>
      <dc:creator>Andrew Merritt_2</dc:creator>
      <dc:date>2005-08-03T08:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915640#M406893</link>
      <description>oops, typo on my part:&lt;BR /&gt;&lt;BR /&gt;result=$(remsh hostname 'cat /tmp/blah 2&amp;gt;/dev/null;echo $?')&lt;BR /&gt;&lt;BR /&gt;I had copied your code and forgot to change that to an echo statement on the end.&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Aug 2005 08:45:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915640#M406893</guid>
      <dc:creator>Pat Lieberg</dc:creator>
      <dc:date>2005-08-03T08:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915641#M406894</link>
      <description>Mike, your code is not right.&lt;BR /&gt;result=$(remsh hostname 'cat /tmp/blah 2&amp;gt;/dev/null; result=$?')&lt;BR /&gt;if [ $result -eq 2 ]&lt;BR /&gt;then&lt;BR /&gt;pageout&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Will just return remsh return code and not the return code of cat command which you excuted on remote host. Do it as follows.&lt;BR /&gt;&lt;BR /&gt;remsh hostname -l user_name 'cat xyz 2&amp;gt;/dev/null;echo $? &amp;gt; /tmp/status' ## Put the return status in a file&lt;BR /&gt;result=$(remsh hostname 'cat /tmp/status')&lt;BR /&gt;if [ $result -eq 2 ]&lt;BR /&gt;then&lt;BR /&gt;pageout&lt;BR /&gt;fi</description>
      <pubDate>Wed, 03 Aug 2005 08:48:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915641#M406894</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2005-08-03T08:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915642#M406895</link>
      <description>Mike's code is correct.  The single quotes around the command passed to remsh guarantee the return code comes from the remote system and not the local remsh command.&lt;BR /&gt;&lt;BR /&gt;I've tested it.</description>
      <pubDate>Wed, 03 Aug 2005 08:52:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915642#M406895</guid>
      <dc:creator>Pat Lieberg</dc:creator>
      <dc:date>2005-08-03T08:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: rsh and return code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915643#M406896</link>
      <description>thanks Pat RAC, Andrew. Working now. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Aug 2005 08:55:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/rsh-and-return-code/m-p/4915643#M406896</guid>
      <dc:creator>Mike_Ca Li</dc:creator>
      <dc:date>2005-08-03T08:55:37Z</dc:date>
    </item>
  </channel>
</rss>

