<?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 Script help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5505871#M640147</link>
    <description>&lt;P&gt;Hi All!&lt;BR /&gt;&lt;BR /&gt;Have the following piece of script , there are atleast 5 URLs that it goes through and sends 5 alerts, I need to have the script send just 1 alert instead of 5. The problem is that if some app is inaccessible from the frontend URLs then I get 5 alerts instead of 1.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; PROD)
    export ENV1=prod1
    export URL1=&lt;A href="http://tools.zzz.com:5555/apache/ww" target="_blank"&gt;http://tools.zzz.com:5555/apache/ww&lt;/A&gt;
    INSTANCES=`showappinst -app FrontEndApache | awk -F: '{print $1}'`
    mon=`showappinst -app FrontEndApache | awk -F: '{print $2}'|head -1`
    for i in $INSTANCES
    do
       curl --connect-timeout 2 -s --retry 3 --retry-delay 10 --max-time 3 "http://$i:$PORT/dest" | egrep "DOWN|INACCESSIBLE"
       curl --connect-timeout 2 -s --retry 3 --retry-delay 10 --max-time 3 "http://$i:$PORT/dest" |egrep -A1 "DOWN|INACCESSIBLE" &amp;gt; /tmp/mon_prod1.tmp
       if [ `echo $?` -eq 0 ]
       then
          echo "&amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;title&amp;gt;destinations list&amp;lt;/title&amp;gt; &amp;lt;/head&amp;gt; &amp;lt;body&amp;gt; &amp;lt;table cellspacing="2" bgcolor="black"&amp;gt; &amp;lt;tr bgcolor="#a0a0a0"&amp;gt; &amp;lt;table&amp;gt; &amp;lt;tr&amp;gt;" &amp;gt; /tmp/mon_${ENV1}.html
          echo $i &amp;gt;&amp;gt; /tmp/mon_${ENV1}.html
          cat /tmp/mon_prod1.tmp &amp;gt;&amp;gt; /tmp/mon_${ENV1}.html
          echo "&amp;lt;/tr&amp;gt; &amp;lt;/table&amp;gt; &amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt;" &amp;gt;&amp;gt; /tmp/mon_${ENV1}.html
          (echo "Subject:$1:Instances inaccessible or down in FrontEndApache"; echo "To:alert@zzz.com"; echo "Content-Type: text/html"; echo "Content-Disposition: inline"; cat /tmp/mon_${ENV1}.html; ) | /usr/sbin/sendmail -t
       fi
       echo -n "" &amp;gt; /tmp/mon_prod1.tmp &amp;gt; /tmp/monalert_${ENV1}.html
    done
 ;;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Thanks,&lt;BR /&gt;Allan.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jan 2012 20:25:45 GMT</pubDate>
    <dc:creator>allanm77</dc:creator>
    <dc:date>2012-01-23T20:25:45Z</dc:date>
    <item>
      <title>Script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5505871#M640147</link>
      <description>&lt;P&gt;Hi All!&lt;BR /&gt;&lt;BR /&gt;Have the following piece of script , there are atleast 5 URLs that it goes through and sends 5 alerts, I need to have the script send just 1 alert instead of 5. The problem is that if some app is inaccessible from the frontend URLs then I get 5 alerts instead of 1.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; PROD)
    export ENV1=prod1
    export URL1=&lt;A href="http://tools.zzz.com:5555/apache/ww" target="_blank"&gt;http://tools.zzz.com:5555/apache/ww&lt;/A&gt;
    INSTANCES=`showappinst -app FrontEndApache | awk -F: '{print $1}'`
    mon=`showappinst -app FrontEndApache | awk -F: '{print $2}'|head -1`
    for i in $INSTANCES
    do
       curl --connect-timeout 2 -s --retry 3 --retry-delay 10 --max-time 3 "http://$i:$PORT/dest" | egrep "DOWN|INACCESSIBLE"
       curl --connect-timeout 2 -s --retry 3 --retry-delay 10 --max-time 3 "http://$i:$PORT/dest" |egrep -A1 "DOWN|INACCESSIBLE" &amp;gt; /tmp/mon_prod1.tmp
       if [ `echo $?` -eq 0 ]
       then
          echo "&amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;title&amp;gt;destinations list&amp;lt;/title&amp;gt; &amp;lt;/head&amp;gt; &amp;lt;body&amp;gt; &amp;lt;table cellspacing="2" bgcolor="black"&amp;gt; &amp;lt;tr bgcolor="#a0a0a0"&amp;gt; &amp;lt;table&amp;gt; &amp;lt;tr&amp;gt;" &amp;gt; /tmp/mon_${ENV1}.html
          echo $i &amp;gt;&amp;gt; /tmp/mon_${ENV1}.html
          cat /tmp/mon_prod1.tmp &amp;gt;&amp;gt; /tmp/mon_${ENV1}.html
          echo "&amp;lt;/tr&amp;gt; &amp;lt;/table&amp;gt; &amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt;" &amp;gt;&amp;gt; /tmp/mon_${ENV1}.html
          (echo "Subject:$1:Instances inaccessible or down in FrontEndApache"; echo "To:alert@zzz.com"; echo "Content-Type: text/html"; echo "Content-Disposition: inline"; cat /tmp/mon_${ENV1}.html; ) | /usr/sbin/sendmail -t
       fi
       echo -n "" &amp;gt; /tmp/mon_prod1.tmp &amp;gt; /tmp/monalert_${ENV1}.html
    done
 ;;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Thanks,&lt;BR /&gt;Allan.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2012 20:25:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5505871#M640147</guid>
      <dc:creator>allanm77</dc:creator>
      <dc:date>2012-01-23T20:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: Script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5505935#M640148</link>
      <description>&lt;P&gt;&amp;gt;I need to have the script send just 1 alert instead of 5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You need to send the message after your loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;mon=`showappinst -app FrontEndApache | awk -F: '{print $2}'|head -1`&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can optimize this to:&lt;/P&gt;&lt;P&gt;mon=$(showappinst -app FrontEndApache | awk -F: '{print $2; exit}')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;typeset -i count_errors=0&lt;/P&gt;&lt;P&gt;for ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure why you are doing two curl commands?&amp;nbsp; Combine to one.&lt;/P&gt;&lt;P&gt;curl --connect-timeout 2 -s --retry 3 --retry-delay 10 --max-time 3 "http://$i:$PORT/dest" | egrep -A1 "DOWN|INACCESSIBLE" &amp;gt; /tmp/mon_prod1.tmp&lt;/P&gt;&lt;P&gt;status=$?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;grep -e DOWN -e INACCESSIBLE /tmp/mon_prod1.tmp&amp;nbsp; # error output for user&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nor why you use echo for $?&amp;nbsp; ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if [ $status -eq 0 ]; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; (( count_errors += 1 ))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if [ $count_errors -eq 1 ]; then&amp;nbsp; # first time header&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo "&amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;title&amp;gt;destinations list&amp;lt;/title&amp;gt; &amp;lt;/head&amp;gt; &amp;lt;body&amp;gt; &amp;lt;table cellspacing="2" bgcolor="black"&amp;gt; &amp;lt;tr bgcolor="#a0a0a0"&amp;gt; &amp;lt;table&amp;gt; &amp;lt;tr&amp;gt;" &amp;gt; /tmp/mon_${ENV1}.html&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; fi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; echo $i &amp;gt;&amp;gt; /tmp/mon_${ENV1}.html&lt;/P&gt;&lt;P&gt;fi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't think you can redirect to two files??&lt;/P&gt;&lt;P&gt;echo -n "" &amp;gt; /tmp/mon_prod1.tmp &amp;gt; /tmp/monalert_${ENV1}.html&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, "echo -n" isn't valid in a real shell.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And after the end of the loop check to send message:&lt;/P&gt;&lt;P&gt;if [ $count_errors -ne 0 ]; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; cat /tmp/mon_prod1.tmp &amp;gt;&amp;gt; /tmp/mon_${ENV1}.html&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; echo "&amp;lt;/tr&amp;gt; &amp;lt;/table&amp;gt; &amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt;" &amp;gt;&amp;gt; /tmp/mon_${ENV1}.html&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; (echo "Subject:$1:Instances inaccessible or down in FrontEndApache"; echo "To:alert@zzz.com"; echo "Content-Type: text/html"; echo "Content-Disposition: inline"; cat /tmp/mon_${ENV1}.html; ) | /usr/sbin/sendmail -t&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; rm -f /tmp/mon_${ENV1}.html # cleanup&lt;/P&gt;&lt;P&gt;fi&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2012 04:34:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5505935#M640148</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-01-24T04:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: Script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5506099#M640149</link>
      <description>Thanks Dennis</description>
      <pubDate>Tue, 24 Jan 2012 01:08:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5506099#M640149</guid>
      <dc:creator>allanm77</dc:creator>
      <dc:date>2012-01-24T01:08:48Z</dc:date>
    </item>
  </channel>
</rss>

