<?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: Background processes result code in HP-UX in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186824#M460811</link>
    <description>Hi (again) Horia:&lt;BR /&gt;&lt;BR /&gt;Make sure to declare your interpreter at the head of the file:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;rc1=$$?&lt;BR /&gt;...should be:&lt;BR /&gt;rc1=$?&lt;BR /&gt;&lt;BR /&gt;Your 'if' statement needs to be:&lt;BR /&gt;&lt;BR /&gt;if [ $rc1 != 0 -o $rc2 != 0 -o $rc3 != 0 -o  $rc4 != 0 -0 $rc5 != 0 ]; then&lt;BR /&gt;echo "Copy was not possible."&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;See the 'test(1)' manpages.&lt;BR /&gt;&lt;BR /&gt;A better form would double-quote the variables to prevent syntax errors if they were undefined (empty).  Enclosing the variable in curly braces is a good habit to develop.  It avoids any ambiguity.&lt;BR /&gt;&lt;BR /&gt;if [ "${rc1}" != 0 -o "${rc2}" != 0 -o "${rc3}" != 0 -o  "${rc4}" != 0 -0 "${rc5}" != 0 ]; then&lt;BR /&gt;echo "Copy was not possible."&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Sun, 12 Jul 2009 11:42:53 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2009-07-12T11:42:53Z</dc:date>
    <item>
      <title>Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186821#M460808</link>
      <description>&lt;!--!*#--&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I have this sh code:&lt;BR /&gt;#-----------------------------&lt;BR /&gt;cp -pr PROD/[a-g,A-G]* $DIR/oradata/PROD/ &amp;amp;&lt;BR /&gt;cp -pr PROD/[h-k,H-K]* $DIR/oradata/PROD/ &amp;amp;&lt;BR /&gt;cp -pr PROD/[m-t,M-T]* $DIR/oradata/PROD/ &amp;amp;&lt;BR /&gt;cp -pr PROD/[u-z,U-Z]* $DIR/oradata/PROD/&lt;BR /&gt; &lt;BR /&gt;wait&lt;BR /&gt;#-----------------------------&lt;BR /&gt;&lt;BR /&gt;How can I find out if some of the cp (any or all and which one) had a problem and exited with a non-zero status?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I have tryed &lt;BR /&gt;&lt;BR /&gt;if [ $? != 0 ] ; then ....&lt;BR /&gt;&lt;BR /&gt;afther wait&lt;BR /&gt;&lt;BR /&gt;But I found out that $? is allways zero when waiting for more than one child.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Horia Chirculescu</description>
      <pubDate>Sat, 11 Jul 2009 17:52:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186821#M460808</guid>
      <dc:creator>Horia Chirculescu</dc:creator>
      <dc:date>2009-07-11T17:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186822#M460809</link>
      <description>Hi Horia:&lt;BR /&gt;&lt;BR /&gt;You need to capture in a variable the pid of each process as you start them.  Then, 'wait()' for the process(es) by pid.  When the 'wait()' is satisfied, you can test '$? to obtain the completed process's return code.  By example:&lt;BR /&gt;&lt;BR /&gt;# cat ./proc.sh&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;./proc_1 &amp;amp;&lt;BR /&gt;PID1=$!&lt;BR /&gt;./proc_2 &amp;amp;&lt;BR /&gt;PID2=$!&lt;BR /&gt;echo "...two processes started -- ${PID1} ${PID2}"&lt;BR /&gt;wait ${PID1}&lt;BR /&gt;echo "process-1 ${PID1} done with rc=$?"&lt;BR /&gt;wait ${PID2}&lt;BR /&gt;echo "process-2 ${PID2} done with rc=$?"&lt;BR /&gt;&lt;BR /&gt;# cat ./proc_1&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;sleep 20&lt;BR /&gt;exit 1&lt;BR /&gt;&lt;BR /&gt;# cat ./proc_2&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;sleep 10&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;# ./proc.sh&lt;BR /&gt;...two processes started -- 14061 14062&lt;BR /&gt;process-1 14061 done with rc=1&lt;BR /&gt;process-2 14062 done with rc=0&lt;BR /&gt;&lt;BR /&gt;...That is, you can do synchronous work; wait for all processes to terminate; and interrogate the return code of each process when it terminates.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sat, 11 Jul 2009 18:32:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186822#M460809</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-07-11T18:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186823#M460810</link>
      <description>&lt;!--!*#--&gt;Hello, James&lt;BR /&gt;&lt;BR /&gt;Glad to meet you.&lt;BR /&gt;&lt;BR /&gt;Here it is my script based on your idea. Any comment may help.&lt;BR /&gt;&lt;BR /&gt;#-----------------------------------------&lt;BR /&gt;mv PROD/log/PROD_* $DIR/oradata/PROD/log &amp;amp;&lt;BR /&gt;PID1=$!&lt;BR /&gt;cp -pr PROD/[a-g,A-G]* $DIR/oradata/PROD/ &amp;amp;&lt;BR /&gt;PID2=$!&lt;BR /&gt;cp -pr PROD/[h-k,H-K]* $DIR/oradata/PROD/ &amp;amp;&lt;BR /&gt;PID3=$!&lt;BR /&gt;cp -pr PROD/[m-t,M-T]* $DIR/oradata/PROD/ &amp;amp;&lt;BR /&gt;PID4=$!&lt;BR /&gt;cp -pr PROD/[u-z,U-Z]* $DIR/oradata/PROD/&lt;BR /&gt;rc5=$?&lt;BR /&gt;&lt;BR /&gt;#Waiting for the background processes to finish&lt;BR /&gt;wait ${PID1}&lt;BR /&gt;rc1=$$?&lt;BR /&gt;wait ${PID2}&lt;BR /&gt;rc2=$?&lt;BR /&gt;wait ${PID3}&lt;BR /&gt;rc3=$?&lt;BR /&gt;wait ${PID4}&lt;BR /&gt;rc4=$?&lt;BR /&gt;&lt;BR /&gt;if [ $rc1 != 0 ] or [ $rc2 != 0 ] or [ $rc3 != 0 ] or [ $rc4 != 0 ] or [ $rc5 != 0 ]&lt;BR /&gt; ; then echo "Copy was not possible."&lt;BR /&gt;&lt;BR /&gt;#-----------------------------------------&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Horia Chirculescu</description>
      <pubDate>Sun, 12 Jul 2009 10:12:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186823#M460810</guid>
      <dc:creator>Horia Chirculescu</dc:creator>
      <dc:date>2009-07-12T10:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186824#M460811</link>
      <description>Hi (again) Horia:&lt;BR /&gt;&lt;BR /&gt;Make sure to declare your interpreter at the head of the file:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;rc1=$$?&lt;BR /&gt;...should be:&lt;BR /&gt;rc1=$?&lt;BR /&gt;&lt;BR /&gt;Your 'if' statement needs to be:&lt;BR /&gt;&lt;BR /&gt;if [ $rc1 != 0 -o $rc2 != 0 -o $rc3 != 0 -o  $rc4 != 0 -0 $rc5 != 0 ]; then&lt;BR /&gt;echo "Copy was not possible."&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;See the 'test(1)' manpages.&lt;BR /&gt;&lt;BR /&gt;A better form would double-quote the variables to prevent syntax errors if they were undefined (empty).  Enclosing the variable in curly braces is a good habit to develop.  It avoids any ambiguity.&lt;BR /&gt;&lt;BR /&gt;if [ "${rc1}" != 0 -o "${rc2}" != 0 -o "${rc3}" != 0 -o  "${rc4}" != 0 -0 "${rc5}" != 0 ]; then&lt;BR /&gt;echo "Copy was not possible."&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 12 Jul 2009 11:42:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186824#M460811</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-07-12T11:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186825#M460812</link>
      <description>&amp;gt;JRF: Your 'if' statement needs to be:&lt;BR /&gt;if [ $rc1 != 0 -o $rc2 != 0 -o $rc3 != 0 -o $rc4 != 0 -0 $rc5 != 0 ]; then&lt;BR /&gt;&lt;BR /&gt;Since these are numeric values and not strings, it should be:&lt;BR /&gt;if [ $rc1 -ne 0 -o $rc2 -ne 0 -o $rc3 -ne 0 -o $rc4 -ne 0 -o $rc5 -ne 0 ]; then</description>
      <pubDate>Sun, 12 Jul 2009 17:38:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186825#M460812</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-07-12T17:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186826#M460813</link>
      <description>&lt;!--!*#--&gt;Dennis,&lt;BR /&gt;&lt;BR /&gt;James is right&lt;BR /&gt; &lt;BR /&gt;[oltsnlo]:/root/Horia/Cluster #  test "0" = 0&lt;BR /&gt;[oltsnlo]:/root/Horia/Cluster #  echo $?&lt;BR /&gt;0&lt;BR /&gt;[oltsnlo]:/root/Horia/Cluster # test "123" = 123&lt;BR /&gt;[oltsnlo]:/root/Horia/Cluster # echo $?&lt;BR /&gt;0&lt;BR /&gt;[oltsnlo]:/root/Horia/Cluster # test 111 = 111&lt;BR /&gt;[oltsnlo]:/root/Horia/Cluster # echo $?&lt;BR /&gt;0&lt;BR /&gt;[oltsnlo]:/root/Horia/Cluster # test "111" = 123&lt;BR /&gt;[oltsnlo]:/root/Horia/Cluster # echo $?&lt;BR /&gt;1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So it seems that it does not matter on this shell (Posix shell).</description>
      <pubDate>Sun, 12 Jul 2009 18:28:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186826#M460813</guid>
      <dc:creator>Horia Chirculescu</dc:creator>
      <dc:date>2009-07-12T18:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186827#M460814</link>
      <description>&amp;gt;Chirculescu: James is right... So it seems that it does not matter on this shell (Posix shell).&lt;BR /&gt;&lt;BR /&gt;There is a difference between strings and numeric values and their comparisons.  There is a difference between something that works in some cases and something that always works.  I wanted to make sure you used the correct syntax for comparing the exit status.&lt;BR /&gt;if [ $? = 00 ]; then&lt;BR /&gt;if [ $? -eq 00 ]; then&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 12 Jul 2009 18:43:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186827#M460814</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-07-12T18:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186828#M460815</link>
      <description>&lt;!--!*#--&gt;Dennis,&lt;BR /&gt;&lt;BR /&gt;It is hard to make a script to "always work" as you suggest.&lt;BR /&gt;&lt;BR /&gt;If I would change the current shell (Posix shell in this case) to be let's say Bourne shell or whatever other shell I do have installed (csh maybe), I do not expect that my script would work.&lt;BR /&gt;&lt;BR /&gt;This is why I use at the beginning of the script the particular shell I use&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;It was suggested also by James. This is not a "must" becouse someone could source the script to whatever shell he want/need and hope that things will go as expected.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Horia Chirculescu.</description>
      <pubDate>Sun, 12 Jul 2009 19:07:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186828#M460815</guid>
      <dc:creator>Horia Chirculescu</dc:creator>
      <dc:date>2009-07-12T19:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186829#M460816</link>
      <description>&amp;gt;It is hard to make a script to "always work" as you suggest.&lt;BR /&gt;&lt;BR /&gt;Not scripts but numeric comparisons.  I assume you know why "9 &amp;gt; 10" but "9 -lt 10".</description>
      <pubDate>Sun, 12 Jul 2009 19:30:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186829#M460816</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-07-12T19:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186830#M460817</link>
      <description>HI (again) Horia:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; It is hard to make a script to "always work" as you suggest.&lt;BR /&gt;&lt;BR /&gt;As Dennis correctly noted, "Not scripts but numeric comparisons.".&lt;BR /&gt;&lt;BR /&gt;Dennis is right.  I should have told you to use the '-ne' operator since a return code is an integer.  The string comparison operator I used works because we are comparing equality, but it isn't good form.&lt;BR /&gt;&lt;BR /&gt;I have always found the shell's use of '-eq', '-lt' and '-gt' for algebraic comparisons while reserving '=', '&amp;lt;' and '&amp;gt;' for string comparisons, to be counterintuitive.  In Perl, the operators are just reversed (without the hyphen too).  While it's a bit of a lame excuse, I do more Perl than shell :-)&lt;BR /&gt;&lt;BR /&gt;See "Conditional Expressions" in:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.hp.com/en/B2355-60130/sh-posix.1.html" target="_blank"&gt;http://docs.hp.com/en/B2355-60130/sh-posix.1.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF... &lt;BR /&gt;</description>
      <pubDate>Sun, 12 Jul 2009 21:19:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186830#M460817</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-07-12T21:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186831#M460818</link>
      <description>Just to add to the confusion... a word of warning on using "wait &lt;PID&gt;" in scripts...&lt;BR /&gt;&lt;BR /&gt;if the command you are intending to wait for *exits* before you call wait, you will *not* get the return code of the process... so for shortlived processes, I tend not to trust wait, and always put some sort of shell wrapper around any background process where I can collect status information (into a file for example)&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Duncan&lt;/PID&gt;</description>
      <pubDate>Mon, 13 Jul 2009 06:00:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186831#M460818</guid>
      <dc:creator>Duncan Edmonstone</dc:creator>
      <dc:date>2009-07-13T06:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186832#M460819</link>
      <description>&lt;!--!*#--&gt;Thank you all for the replys.&lt;BR /&gt;&lt;BR /&gt;I will close this thread as it it clear now.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Horia Chirculescu&lt;BR /&gt;Vianet Serv SRL.</description>
      <pubDate>Mon, 13 Jul 2009 09:00:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186832#M460819</guid>
      <dc:creator>Horia Chirculescu</dc:creator>
      <dc:date>2009-07-13T09:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186833#M460820</link>
      <description>Thread closed.</description>
      <pubDate>Mon, 13 Jul 2009 09:00:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186833#M460820</guid>
      <dc:creator>Horia Chirculescu</dc:creator>
      <dc:date>2009-07-13T09:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Background processes result code in HP-UX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186834#M460821</link>
      <description>&amp;gt;JRF: I have always found the shell's use of '-eq', '-lt' and '-gt' ..., to be counterintuitive.&lt;BR /&gt;&lt;BR /&gt;If you are only doing numeric comparisons, then you can switch to C style:&lt;BR /&gt;if (( rc1 != 0 || rc2 != 0 || rc3 != 0 || rc4 != 0 || rc5 != 0 )); then&lt;BR /&gt;&lt;BR /&gt;Or if you think these are boolean values:&lt;BR /&gt;if (( rc1 || rc2 || rc3 || rc4 || rc5 )); then&lt;BR /&gt;</description>
      <pubDate>Fri, 01 Jan 2010 20:15:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/background-processes-result-code-in-hp-ux/m-p/5186834#M460821</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-01-01T20:15:42Z</dc:date>
    </item>
  </channel>
</rss>

