<?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: running scripts at background by order in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/running-scripts-at-background-by-order/m-p/2757032#M71645</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;At the beginning of your script, check whether other instances of your script are running and if they are, check the PID of these instances. At the end of your script run, check that all these PIDs have disappeared from the ps output before exiting.&lt;BR /&gt;&lt;BR /&gt;Of my head (you need to test and refine):&lt;BR /&gt;&lt;BR /&gt;#!/sbin/sh&lt;BR /&gt;&lt;BR /&gt;PIDS=`ps -fae | grep my_script | grep -v grep | awk '{print $2}'`&lt;BR /&gt;&lt;BR /&gt;... # whatever your script runs here&lt;BR /&gt;&lt;BR /&gt;# Exit only when other instances have completed&lt;BR /&gt;&lt;BR /&gt;pidlist=&lt;BR /&gt;for pid in `echo $PIDS`&lt;BR /&gt;do&lt;BR /&gt;  pidlist="$pidlist -e $pid"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;while sleep 5 &lt;BR /&gt;do&lt;BR /&gt;  if ! ps -fae | awk '{print $2}' | grep $pidlist &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;  then&lt;BR /&gt;    # none of the forerunning processes are alive&lt;BR /&gt;    exit&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong</description>
    <pubDate>Wed, 03 Jul 2002 10:25:24 GMT</pubDate>
    <dc:creator>Steven Sim Kok Leong</dc:creator>
    <dc:date>2002-07-03T10:25:24Z</dc:date>
    <item>
      <title>running scripts at background by order</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/running-scripts-at-background-by-order/m-p/2757031#M71644</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I'm trying to run a script that submit by many users. it is very important to keep the order (FIFO).&lt;BR /&gt;I tried the   'script | at now' and queuedefs 1j (only 1 job at a time). but when a few jobs send one after the other in short time, It does not keep the order.&lt;BR /&gt;&lt;BR /&gt;any idea?&lt;BR /&gt;Thanks in advance,&lt;BR /&gt;Perez Ilan.</description>
      <pubDate>Wed, 03 Jul 2002 10:09:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/running-scripts-at-background-by-order/m-p/2757031#M71644</guid>
      <dc:creator>perez Ilan</dc:creator>
      <dc:date>2002-07-03T10:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: running scripts at background by order</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/running-scripts-at-background-by-order/m-p/2757032#M71645</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;At the beginning of your script, check whether other instances of your script are running and if they are, check the PID of these instances. At the end of your script run, check that all these PIDs have disappeared from the ps output before exiting.&lt;BR /&gt;&lt;BR /&gt;Of my head (you need to test and refine):&lt;BR /&gt;&lt;BR /&gt;#!/sbin/sh&lt;BR /&gt;&lt;BR /&gt;PIDS=`ps -fae | grep my_script | grep -v grep | awk '{print $2}'`&lt;BR /&gt;&lt;BR /&gt;... # whatever your script runs here&lt;BR /&gt;&lt;BR /&gt;# Exit only when other instances have completed&lt;BR /&gt;&lt;BR /&gt;pidlist=&lt;BR /&gt;for pid in `echo $PIDS`&lt;BR /&gt;do&lt;BR /&gt;  pidlist="$pidlist -e $pid"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;while sleep 5 &lt;BR /&gt;do&lt;BR /&gt;  if ! ps -fae | awk '{print $2}' | grep $pidlist &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;  then&lt;BR /&gt;    # none of the forerunning processes are alive&lt;BR /&gt;    exit&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong</description>
      <pubDate>Wed, 03 Jul 2002 10:25:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/running-scripts-at-background-by-order/m-p/2757032#M71645</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2002-07-03T10:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: running scripts at background by order</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/running-scripts-at-background-by-order/m-p/2757033#M71646</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I forgot to consider the currently running script. &lt;BR /&gt;&lt;BR /&gt;Change:&lt;BR /&gt;&lt;BR /&gt;PIDS=`ps -fae | grep my_script | grep -v grep | awk '{print $2}'` &lt;BR /&gt;&lt;BR /&gt;To:&lt;BR /&gt;&lt;BR /&gt;PIDS=`ps -fae | grep my_script | grep -v grep | awk '{print $2}' | grep -v $$` &lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong</description>
      <pubDate>Wed, 03 Jul 2002 10:28:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/running-scripts-at-background-by-order/m-p/2757033#M71646</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2002-07-03T10:28:37Z</dc:date>
    </item>
  </channel>
</rss>

