<?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: AND, OR with IF and GREP - statements in shell scripting in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737849#M655765</link>
    <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;you have a mistake in your script.&lt;BR /&gt;&lt;BR /&gt;"grep -c" return a count of matching lines.&lt;BR /&gt;You should replace:&lt;BR /&gt;RDS=`grep -c rds output-file | grep -c Down`&lt;BR /&gt;CRS=`grep -c crs output-file | grep -c Down`&lt;BR /&gt;MMD=`grep -c mmd output-file | grep -c Down`&lt;BR /&gt;KMS=`grep -c kms output-file | grep -c Down`&lt;BR /&gt;by (remove 1st "-c"):&lt;BR /&gt;RDS=`grep rds output-file | grep -c Down`&lt;BR /&gt;CRS=`grep crs output-file | grep -c Down`&lt;BR /&gt;MMD=`grep mmd output-file | grep -c Down`&lt;BR /&gt;KMS=`grep kms output-file | grep -c Down`&lt;BR /&gt;&lt;BR /&gt;My suggestion:&lt;BR /&gt;if grep -qE '^(rds|crs|mmd|kms) : Down' output-file&lt;BR /&gt;then&lt;BR /&gt; echo ...&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Mounaam</description>
    <pubDate>Thu, 13 Jan 2011 13:09:51 GMT</pubDate>
    <dc:creator>Mounaam</dc:creator>
    <dc:date>2011-01-13T13:09:51Z</dc:date>
    <item>
      <title>AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737842#M655758</link>
      <description>Hi, &lt;BR /&gt;Please suggest about:&lt;BR /&gt;1. AND, OR operations inside an IF condition&lt;BR /&gt;2. AND, OR operations inside GREP&lt;BR /&gt;&lt;BR /&gt;AND and OR operations give confusions and issues all the times(which braket"(" or "[[" or, ,,etc,...). can you please write how to use them with simple examples.&lt;BR /&gt;&lt;BR /&gt;ISSUE: i have this output in a file(output-file). i would like to run an opcmsg if either rds, crs, mmd or kms is down.&lt;BR /&gt;&lt;BR /&gt;OUTPUT-FILE:&lt;BR /&gt;**************&lt;BR /&gt;oper@corvette:/home/oper=&amp;gt;omnisv -status&lt;BR /&gt;   ProcName  Status  [PID]&lt;BR /&gt;===============================&lt;BR /&gt;    rds     : Down&lt;BR /&gt;    crs     : Active  [9569]&lt;BR /&gt;    mmd     : Active  [9566]&lt;BR /&gt;    kms     : Active  [9567]&lt;BR /&gt;    omnitrig: Active&lt;BR /&gt;    uiproxy : Active  [9571]&lt;BR /&gt;===============================&lt;BR /&gt;Status: At least one of Data Protector relevant processes/services is not running.&lt;BR /&gt;**************&lt;BR /&gt;&lt;BR /&gt;i wrote like this:&lt;BR /&gt;RDS=`grep -c rds output-file | grep -c Down`&lt;BR /&gt;CRS=`grep -c crs output-file | grep -c Down`&lt;BR /&gt;MMD=`grep -c mmd output-file | grep -c Down`&lt;BR /&gt;KMS=`grep -c kms output-file | grep -c Down`&lt;BR /&gt;&lt;BR /&gt;if[[ $RDS -eq 1 || $CRS -eq 1 || $MMD -eq 1 || $KMS -eq 1 ]]&lt;BR /&gt;then&lt;BR /&gt;echo "At least one of Data Protector relevant processes/services is not running."&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jan 2011 11:59:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737842#M655758</guid>
      <dc:creator>sekar sundaram</dc:creator>
      <dc:date>2011-01-13T11:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737843#M655759</link>
      <description>This might sound simplistic but you could just grep your file for "Down" and mail yourself an alert:&lt;BR /&gt;&lt;BR /&gt;grep -i down &lt;PATH&gt;&lt;/PATH&gt;&lt;BR /&gt;Just a thought,&lt;BR /&gt;Rita&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jan 2011 12:08:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737843#M655759</guid>
      <dc:creator>Rita C Workman</dc:creator>
      <dc:date>2011-01-13T12:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737844#M655760</link>
      <description>typo...&lt;BR /&gt;&lt;BR /&gt;grep -i down &lt;PATH&gt;&lt;/PATH&gt;&lt;BR /&gt;should read&lt;BR /&gt;&lt;BR /&gt;grep -i down &lt;PATH&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Boy I hate giving up coffee....&lt;BR /&gt;/rcw&lt;/PATH&gt;</description>
      <pubDate>Thu, 13 Jan 2011 12:09:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737844#M655760</guid>
      <dc:creator>Rita C Workman</dc:creator>
      <dc:date>2011-01-13T12:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737845#M655761</link>
      <description>Be a simplest comparation:&lt;BR /&gt;&lt;BR /&gt;if [ "${RDS}${CRD}${MMD}${KMS}" != "0000" ]&lt;BR /&gt;then&lt;BR /&gt;   echo "At least one of Data Protector relevant processes/services is not running."&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Rgds.</description>
      <pubDate>Thu, 13 Jan 2011 12:24:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737845#M655761</guid>
      <dc:creator>Jose Mosquera</dc:creator>
      <dc:date>2011-01-13T12:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737846#M655762</link>
      <description>Rita,&lt;BR /&gt;ya, presently i am doing the same thing - i am grep'ing for 4 "Active" and if its less, i am running few other commands.&lt;BR /&gt;issue is that the other two processes uiproxy and omnitrig need not be monitored.. i want to monitor only 4 processes, that is the issue.&lt;BR /&gt;&lt;BR /&gt;Also please advice how to use AND and OR operators with IF and GREP.&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jan 2011 12:36:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737846#M655762</guid>
      <dc:creator>sekar sundaram</dc:creator>
      <dc:date>2011-01-13T12:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737847#M655763</link>
      <description>Sekar,&lt;BR /&gt;&lt;BR /&gt;You question was:&lt;BR /&gt;AND and OR operations give confusions and issues all the times(which braket"(" or "[[" or, ,,etc,...). can you please write how to use them with simple examples.&lt;BR /&gt;&lt;BR /&gt;..take a look at Jose wrote it and you have a good answer of your request for a  simple example..&lt;BR /&gt;&lt;BR /&gt;Rgrds,&lt;BR /&gt;Rita</description>
      <pubDate>Thu, 13 Jan 2011 13:03:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737847#M655763</guid>
      <dc:creator>Rita C Workman</dc:creator>
      <dc:date>2011-01-13T13:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737848#M655764</link>
      <description>Jose, that worked !!!&lt;BR /&gt;&lt;BR /&gt;the script now&lt;BR /&gt;RDS=`grep rds testfile | grep -c Down`&lt;BR /&gt;CRS=`grep crs testfile | grep -c Down`&lt;BR /&gt;MMD=`grep mmd testfile | grep -c Down`&lt;BR /&gt;KMS=`grep kms testfile | grep -c Down`&lt;BR /&gt;&lt;BR /&gt;if [ "${RDS}${CRS}${MMD}${KMS}" != "0000" ]                             i&lt;BR /&gt;then&lt;BR /&gt;echo "At least one process is not running"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;between, still you can reply about - &lt;BR /&gt;How to use to AND and OR, with GREP and IF ?&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jan 2011 13:05:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737848#M655764</guid>
      <dc:creator>sekar sundaram</dc:creator>
      <dc:date>2011-01-13T13:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737849#M655765</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;you have a mistake in your script.&lt;BR /&gt;&lt;BR /&gt;"grep -c" return a count of matching lines.&lt;BR /&gt;You should replace:&lt;BR /&gt;RDS=`grep -c rds output-file | grep -c Down`&lt;BR /&gt;CRS=`grep -c crs output-file | grep -c Down`&lt;BR /&gt;MMD=`grep -c mmd output-file | grep -c Down`&lt;BR /&gt;KMS=`grep -c kms output-file | grep -c Down`&lt;BR /&gt;by (remove 1st "-c"):&lt;BR /&gt;RDS=`grep rds output-file | grep -c Down`&lt;BR /&gt;CRS=`grep crs output-file | grep -c Down`&lt;BR /&gt;MMD=`grep mmd output-file | grep -c Down`&lt;BR /&gt;KMS=`grep kms output-file | grep -c Down`&lt;BR /&gt;&lt;BR /&gt;My suggestion:&lt;BR /&gt;if grep -qE '^(rds|crs|mmd|kms) : Down' output-file&lt;BR /&gt;then&lt;BR /&gt; echo ...&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Mounaam</description>
      <pubDate>Thu, 13 Jan 2011 13:09:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737849#M655765</guid>
      <dc:creator>Mounaam</dc:creator>
      <dc:date>2011-01-13T13:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737850#M655766</link>
      <description>Another simple way...&lt;BR /&gt;&lt;BR /&gt;RDS=`cat output-file|grep -q ^"rds : Down"|echo $?`&lt;BR /&gt;CRS=`cat output-file|grep -q ^"crs : Down"|echo $?`&lt;BR /&gt;MMD=`cat output-file|grep -q ^"mmd : Down"|echo $?`&lt;BR /&gt;KMS=`cat output-file|grep -q ^"kms : Down"|echo $?`&lt;BR /&gt;&lt;BR /&gt;if [ "${RDS}${CRD}${MMD}${KMS}" != "0000" ]&lt;BR /&gt;then&lt;BR /&gt;echo "At least one of Data Protector relevant processes/services is not running."&lt;BR /&gt;fi</description>
      <pubDate>Thu, 13 Jan 2011 13:10:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737850#M655766</guid>
      <dc:creator>Jose Mosquera</dc:creator>
      <dc:date>2011-01-13T13:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737851#M655767</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;For 'and' and 'or' operators within an 'if' condition, you should read the section of the 'sh-posix(1) manpages entitled "conditional expressions" as well as the manpages for 'test(1)'.&lt;BR /&gt;&lt;BR /&gt;The 'grep' command can perform regular expression alternation (an 'or') like this (using your example:&lt;BR /&gt;&lt;BR /&gt;# grep -E "rds : Down|crs : Down|mmd : Down|mks : Down" filename &amp;amp;&amp;amp; echo "at least one down" || echo "all ok"&lt;BR /&gt;&lt;BR /&gt;...or with :&lt;BR /&gt;&lt;BR /&gt;grep -e "rds : Down" -e "crs : Down" -e "mmd : Down" -e "mks : Down" filename &amp;amp;&amp;amp; echo "at least one down" || echo "all ok"&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 14 Jan 2011 03:20:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737851#M655767</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-01-14T03:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737852#M655768</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;You can emulate 'and' operations with 'grep' by counting matches.  Using your data, you might do:&lt;BR /&gt;&lt;BR /&gt;if [ $(grep -E "rds :|crs :|mmd :|kms :" filename|grep -c Active) = 4 ]; then&lt;BR /&gt;    echo "all ok"&lt;BR /&gt;else&lt;BR /&gt;     echo "at least one down"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Jan 2011 04:42:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737852#M655768</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-01-14T04:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: AND, OR with IF and GREP - statements in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737853#M655769</link>
      <description>&amp;gt;JRF: You can emulate 'and' operations with 'grep' by counting matches.&lt;BR /&gt;&amp;gt;if [ $(grep -E "rds :|crs :|mmd :|kms :" filename | grep -c Active) = 4 ]&lt;BR /&gt;&lt;BR /&gt;This will check for 4 types of lines.  And if there are exactly 4 that have "Active", even if all are "rds :".&lt;BR /&gt;(And you should replace that "=" by -eq.)&lt;BR /&gt;&lt;BR /&gt;If you want to do AND operations on lines, you can match patterns.  (Only need one if you know the order. :-)&lt;BR /&gt;grep -e "pattern1.*pattern2" -e "pattern2.*pattern1" file&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 15 Jan 2011 08:24:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/and-or-with-if-and-grep-statements-in-shell-scripting/m-p/4737853#M655769</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-01-15T08:24:32Z</dc:date>
    </item>
  </channel>
</rss>

