<?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: Getting pid and return code of the called script within script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-pid-and-return-code-of-the-called-script-within-script/m-p/4897514#M403489</link>
    <description>Hi Rui,&lt;BR /&gt;&lt;BR /&gt;I created a same construction, only with functions.&lt;BR /&gt;In the function called in the background, I fill the variable PROG, which I monitor in the function below.&lt;BR /&gt;TIMEOUT=10&lt;BR /&gt;MAX_TIMEOUT=3600 #one hour&lt;BR /&gt;  # Monitor the proces&lt;BR /&gt;  while (( $(UNIX95= ps -xC $(basename ${PROG}) |grep ${ORACLE_SID} |wc -w) &amp;gt; 0 ))&lt;BR /&gt;  do&lt;BR /&gt;    # wait for the timeout period&lt;BR /&gt;    sleep ${TIMEOUT}&lt;BR /&gt;&lt;BR /&gt;    # update counter with one&lt;BR /&gt;    (( counter +=1 ))&lt;BR /&gt;&lt;BR /&gt;    # calculate total waiting time&lt;BR /&gt;    (( wait_time=${counter}*${TIMEOUT} ))&lt;BR /&gt;&lt;BR /&gt;    # Show feedback as a dot every timeout time&lt;BR /&gt;  printf  "."&lt;BR /&gt;&lt;BR /&gt;    if (( ${wait_time} &amp;gt; ${MAX_TIMEOUT} ))&lt;BR /&gt;    then&lt;BR /&gt;      print "Killing  ${ORACLE_SID} backup process after ${wait_time} seconds"&lt;BR /&gt;      kill ${backup_process}&lt;BR /&gt;    fi&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt;Another possibility is to use the command jobs, i.e. :&lt;BR /&gt; while (( $(jobs | wc -l) &amp;gt; 0 ))&lt;BR /&gt;  do&lt;BR /&gt;    # wait for the timeout period&lt;BR /&gt;    sleep ${TIMEOUT}&lt;BR /&gt;&lt;BR /&gt;    # update counter with one&lt;BR /&gt;    (( counter +=1 ))&lt;BR /&gt;&lt;BR /&gt;    # calculate total waiting time&lt;BR /&gt;    (( wait_time=${counter}*${TIMEOUT} ))&lt;BR /&gt;&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt;Hope it helps,&lt;BR /&gt;&lt;BR /&gt;Renarios</description>
    <pubDate>Thu, 21 Apr 2005 07:15:10 GMT</pubDate>
    <dc:creator>renarios</dc:creator>
    <dc:date>2005-04-21T07:15:10Z</dc:date>
    <item>
      <title>Getting pid and return code of the called script within script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-pid-and-return-code-of-the-called-script-within-script/m-p/4897513#M403488</link>
      <description>Greetings,&lt;BR /&gt;&lt;BR /&gt;I am writing a shell script in which I need to call another shell script.&lt;BR /&gt;However I need to check the pid and the return code of the called script.&lt;BR /&gt;&lt;BR /&gt;I should look like as:&lt;BR /&gt;&lt;BR /&gt;$WORKING_DIRECTORY/script.sh &amp;amp;&lt;BR /&gt;pid=$!&lt;BR /&gt;wait&lt;BR /&gt;ReturnCode=$?&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;My problem is that I am not able to get in ReturnCode the exit code of script.sh?&lt;BR /&gt;&lt;BR /&gt;Any help/suggestion is highly appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance for your help,&lt;BR /&gt;&lt;BR /&gt;Kind Regards,&lt;BR /&gt;&lt;BR /&gt;Rui Vilao.</description>
      <pubDate>Thu, 21 Apr 2005 06:56:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-pid-and-return-code-of-the-called-script-within-script/m-p/4897513#M403488</guid>
      <dc:creator>Rui Vilao</dc:creator>
      <dc:date>2005-04-21T06:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: Getting pid and return code of the called script within script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-pid-and-return-code-of-the-called-script-within-script/m-p/4897514#M403489</link>
      <description>Hi Rui,&lt;BR /&gt;&lt;BR /&gt;I created a same construction, only with functions.&lt;BR /&gt;In the function called in the background, I fill the variable PROG, which I monitor in the function below.&lt;BR /&gt;TIMEOUT=10&lt;BR /&gt;MAX_TIMEOUT=3600 #one hour&lt;BR /&gt;  # Monitor the proces&lt;BR /&gt;  while (( $(UNIX95= ps -xC $(basename ${PROG}) |grep ${ORACLE_SID} |wc -w) &amp;gt; 0 ))&lt;BR /&gt;  do&lt;BR /&gt;    # wait for the timeout period&lt;BR /&gt;    sleep ${TIMEOUT}&lt;BR /&gt;&lt;BR /&gt;    # update counter with one&lt;BR /&gt;    (( counter +=1 ))&lt;BR /&gt;&lt;BR /&gt;    # calculate total waiting time&lt;BR /&gt;    (( wait_time=${counter}*${TIMEOUT} ))&lt;BR /&gt;&lt;BR /&gt;    # Show feedback as a dot every timeout time&lt;BR /&gt;  printf  "."&lt;BR /&gt;&lt;BR /&gt;    if (( ${wait_time} &amp;gt; ${MAX_TIMEOUT} ))&lt;BR /&gt;    then&lt;BR /&gt;      print "Killing  ${ORACLE_SID} backup process after ${wait_time} seconds"&lt;BR /&gt;      kill ${backup_process}&lt;BR /&gt;    fi&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt;Another possibility is to use the command jobs, i.e. :&lt;BR /&gt; while (( $(jobs | wc -l) &amp;gt; 0 ))&lt;BR /&gt;  do&lt;BR /&gt;    # wait for the timeout period&lt;BR /&gt;    sleep ${TIMEOUT}&lt;BR /&gt;&lt;BR /&gt;    # update counter with one&lt;BR /&gt;    (( counter +=1 ))&lt;BR /&gt;&lt;BR /&gt;    # calculate total waiting time&lt;BR /&gt;    (( wait_time=${counter}*${TIMEOUT} ))&lt;BR /&gt;&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt;Hope it helps,&lt;BR /&gt;&lt;BR /&gt;Renarios</description>
      <pubDate>Thu, 21 Apr 2005 07:15:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-pid-and-return-code-of-the-called-script-within-script/m-p/4897514#M403489</guid>
      <dc:creator>renarios</dc:creator>
      <dc:date>2005-04-21T07:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Getting pid and return code of the called script within script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-pid-and-return-code-of-the-called-script-within-script/m-p/4897515#M403490</link>
      <description>Rui,&lt;BR /&gt;&lt;BR /&gt;First off, to be careful you should do this:&lt;BR /&gt;&lt;BR /&gt;$WORKING_DIRECTORY/script.sh &amp;amp;&lt;BR /&gt;pid=$!&lt;BR /&gt;wait $pid&lt;BR /&gt;ReturnCode=$?&lt;BR /&gt;&lt;BR /&gt;IIRC, one of the problems with the wait command is that it only returns the RC of the child process if it is executed *before* the script exits. Given the way UNIX functions, this will not necessarily be the case - (if script.sh exits very quickly for instance). \&lt;BR /&gt;&lt;BR /&gt;In these situations I've always had my child processes write their status to a temp file which I can the read from the parent process - a kludge I know, but much more likely to work.&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Duncan</description>
      <pubDate>Thu, 21 Apr 2005 07:21:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-pid-and-return-code-of-the-called-script-within-script/m-p/4897515#M403490</guid>
      <dc:creator>Duncan Edmonstone</dc:creator>
      <dc:date>2005-04-21T07:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Getting pid and return code of the called script within script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-pid-and-return-code-of-the-called-script-within-script/m-p/4897516#M403491</link>
      <description>&lt;BR /&gt;Prblem solved thanks to Duncan &amp;amp; Renarios!&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Rui.</description>
      <pubDate>Thu, 21 Apr 2005 08:07:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-pid-and-return-code-of-the-called-script-within-script/m-p/4897516#M403491</guid>
      <dc:creator>Rui Vilao</dc:creator>
      <dc:date>2005-04-21T08:07:53Z</dc:date>
    </item>
  </channel>
</rss>

