<?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: Where to keep 'for loop'  in given script ? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/where-to-keep-for-loop-in-given-script/m-p/4721650#M655263</link>
    <description>&lt;!--!*#--&gt;Is there a different expected count for each service? &lt;BR /&gt;&lt;BR /&gt;The logic could be:&lt;BR /&gt;&lt;BR /&gt;Initialize&lt;BR /&gt;   Establish intial coutn for each service&lt;BR /&gt;&lt;BR /&gt;While true;&lt;BR /&gt;   for x y z ; do&lt;BR /&gt;      get count&lt;BR /&gt;      compare count to previous count&lt;BR /&gt;      if conditions aren't favorable, log message&lt;BR /&gt;      set previous to this&lt;BR /&gt;   done&lt;BR /&gt;   delay&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Sat, 04 Dec 2010 07:02:03 GMT</pubDate>
    <dc:creator>Earl_Crowder</dc:creator>
    <dc:date>2010-12-04T07:02:03Z</dc:date>
    <item>
      <title>Where to keep 'for loop'  in given script ?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/where-to-keep-for-loop-in-given-script/m-p/4721649#M655262</link>
      <description># /usr/local/bin/sh&lt;BR /&gt;&lt;BR /&gt;. /usr/local/bin/oraenv_DVEC6FIN&lt;BR /&gt;&lt;BR /&gt;Declare&lt;BR /&gt;expected_count=50 &lt;BR /&gt;current_count=`echo "psc" | tmadmin 2&amp;gt;/dev/null | grep ASYNCDECISI | wc -l` &lt;BR /&gt;if [ $current_count -lt $expected_count ] &lt;BR /&gt;then &lt;BR /&gt;        echo alert &amp;gt; alert.log &lt;BR /&gt;fi &lt;BR /&gt;&lt;BR /&gt;prev_count=$current_count &lt;BR /&gt;&lt;BR /&gt;while [ 1 ] &lt;BR /&gt;do      &lt;BR /&gt;        current_count=`echo "psc" | tmadmin 2&amp;gt;/dev/null | grep ASYNCDECISI | wc -l` &lt;BR /&gt;&lt;BR /&gt;        if [ $current_count -lt $prev_count ] &amp;amp;&amp;amp; [ $current_count -lt $expected_count ] &lt;BR /&gt;        then &lt;BR /&gt;                echo alert &amp;gt; alert.log  &lt;BR /&gt;        fi &lt;BR /&gt;&lt;BR /&gt;        if [ $prev_count -ne $current_count ] &lt;BR /&gt;        then &lt;BR /&gt;                prev_count=$current_count &lt;BR /&gt;        fi &lt;BR /&gt;        sleep 5 &lt;BR /&gt;done&lt;BR /&gt;_______________________________________________&lt;BR /&gt;&lt;BR /&gt;The above script is perfectly working (infinite) script. In which I wanted to include below for loop.&lt;BR /&gt;so that I can reduce number of scripts.&lt;BR /&gt;&lt;BR /&gt;I tried keeping for loop after above while statement which didnt work. Pelase advice where I can keep this for for loop staement in the above scritp.&lt;BR /&gt;&lt;BR /&gt;_______________________________________________&lt;BR /&gt;&lt;BR /&gt;#Monitor count 12 services&lt;BR /&gt;SERVICE12="CANCELAPPLI FULLBATCHAPP GETBATCHDEC GETMULTIROWS OPTPAPERTCS PERSONALPRI TERMSIGNED"&lt;BR /&gt;&lt;BR /&gt;for i in ${SERVICE12}&lt;BR /&gt;do&lt;BR /&gt;        current_count=$(echo "psc" | tmadmin 2&amp;gt;/dev/null | grep -s -c ${i}) &lt;BR /&gt;&lt;BR /&gt; done</description>
      <pubDate>Sat, 04 Dec 2010 02:57:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/where-to-keep-for-loop-in-given-script/m-p/4721649#M655262</guid>
      <dc:creator>Archana1</dc:creator>
      <dc:date>2010-12-04T02:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Where to keep 'for loop'  in given script ?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/where-to-keep-for-loop-in-given-script/m-p/4721650#M655263</link>
      <description>&lt;!--!*#--&gt;Is there a different expected count for each service? &lt;BR /&gt;&lt;BR /&gt;The logic could be:&lt;BR /&gt;&lt;BR /&gt;Initialize&lt;BR /&gt;   Establish intial coutn for each service&lt;BR /&gt;&lt;BR /&gt;While true;&lt;BR /&gt;   for x y z ; do&lt;BR /&gt;      get count&lt;BR /&gt;      compare count to previous count&lt;BR /&gt;      if conditions aren't favorable, log message&lt;BR /&gt;      set previous to this&lt;BR /&gt;   done&lt;BR /&gt;   delay&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 04 Dec 2010 07:02:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/where-to-keep-for-loop-in-given-script/m-p/4721650#M655263</guid>
      <dc:creator>Earl_Crowder</dc:creator>
      <dc:date>2010-12-04T07:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Where to keep 'for loop'  in given script ?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/where-to-keep-for-loop-in-given-script/m-p/4721651#M655264</link>
      <description>&lt;!--!*#--&gt;Hi:&lt;BR /&gt;&lt;BR /&gt;It would seem that you want to include the same logic for the "SERVICE12" list as you do for "ASYNCDECISI".  If that's correct, I would declare your 'count' variables as arrays to match their elements with the list of "services' (including ASYNCDECISI).&lt;BR /&gt;&lt;BR /&gt;The syntax:&lt;BR /&gt;&lt;BR /&gt;# current_count=$(echo "psc" | tmadmin 2&amp;gt;/dev/null | grep -s -c ${i}) &lt;BR /&gt;&lt;BR /&gt;...is the modern syntax to replace archaic backticks like:&lt;BR /&gt;&lt;BR /&gt;# current_count=`echo "psc" | tmadmin 2&amp;gt;/dev/null | grep ASYNCDECISI | wc -l` &lt;BR /&gt;&lt;BR /&gt;Equally important, the first variation eliminates an extra process of 'wc' since 'grep' can return a count of matches it finds (as shown).  Thus for two reasons, the first variation is far preferable to the second.&lt;BR /&gt;&lt;BR /&gt;There is no sense to doing:&lt;BR /&gt;&lt;BR /&gt;if [ $prev_count -ne $current_count ]&lt;BR /&gt;then&lt;BR /&gt;prev_count=$current_count&lt;BR /&gt;fi &lt;BR /&gt;&lt;BR /&gt;...Simply do:&lt;BR /&gt;&lt;BR /&gt;prev_count=$current_count&lt;BR /&gt;&lt;BR /&gt;Thus, in all, you might do:&lt;BR /&gt;&lt;BR /&gt;while [ 1 ]&lt;BR /&gt;do&lt;BR /&gt;    set -A current_count 0 0 0 0 0 0 0 0&lt;BR /&gt;    set -A prev_count 0 0 0 0 0 0 0 0&lt;BR /&gt;    which=0&lt;BR /&gt;    SERVICE12="ASYNCDECISI CANCELAPPLI FULLBATCHAPP GETBATCHDEC GETMULTIROWS OPTPAPERTCS PERSONALPRI TERMSIGNED"&lt;BR /&gt;    for i in ${SERVICE12}&lt;BR /&gt;    do&lt;BR /&gt;        which=$((which+1))&lt;BR /&gt;        current_count[$which]=$(echo "psc" | tmadmin 2&amp;gt;/dev/null | grep -s -c ${i})&lt;BR /&gt;    ...&lt;BR /&gt;    done # with for loop&lt;BR /&gt;    sleep 5&lt;BR /&gt;done # with while loop&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sat, 04 Dec 2010 14:05:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/where-to-keep-for-loop-in-given-script/m-p/4721651#M655264</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-12-04T14:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Where to keep 'for loop'  in given script ?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/where-to-keep-for-loop-in-given-script/m-p/4721652#M655265</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;There's an obvious, silly mistake in the code snippet I suggested.  We certainly don't want to initialize the count arrays every time.  I meant to write:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;set -A current_count 0 0 0 0 0 0 0 0&lt;BR /&gt;set -A prev_count 0 0 0 0 0 0 0 0&lt;BR /&gt;SERVICE12="ASYNCDECISI CANCELAPPLI FULLBATCHAPP GETBATCHDEC GETMULTIROWS OPTPAPERTCS PERSONALPRI TERMSIGNED"&lt;BR /&gt;while [ 1 ]&lt;BR /&gt;do&lt;BR /&gt;    which=0&lt;BR /&gt;    for i in ${SERVICE12}&lt;BR /&gt;    do&lt;BR /&gt;        which=$((which+1))&lt;BR /&gt;        current_count[$which]=$(echo "psc" | tmadmin 2&amp;gt;/dev/null | grep -s -c ${i})&lt;BR /&gt;    ...&lt;BR /&gt;    done # with for loop&lt;BR /&gt;    sleep 5&lt;BR /&gt;done # with while loop&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sat, 04 Dec 2010 14:29:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/where-to-keep-for-loop-in-given-script/m-p/4721652#M655265</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-12-04T14:29:12Z</dc:date>
    </item>
  </channel>
</rss>

