<?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: grep in script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174463#M161749</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;If you would like to grep multiple lines, then you would need to use "-E", extended regular expressions. For ex.,&lt;BR /&gt;&lt;BR /&gt;grep -E -i 'already exists|parameter not set' $BACKUP_LOG&lt;BR /&gt;&lt;BR /&gt;etc&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;BR /&gt;</description>
    <pubDate>Mon, 26 Jan 2004 17:26:31 GMT</pubDate>
    <dc:creator>Sridhar Bhaskarla</dc:creator>
    <dc:date>2004-01-26T17:26:31Z</dc:date>
    <item>
      <title>grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174460#M161746</link>
      <description>I am setting up a script that greps for certain words and if they exist, the file is mailed.&lt;BR /&gt;But I am having problems setting the script up.&lt;BR /&gt;&lt;BR /&gt;if [ -f $BACKUP_LOG ]&lt;BR /&gt;   then&lt;BR /&gt;     if [ `grep -i`  '"already exits" | "parameter not set" | "find: cannot get"&lt;BR /&gt;       | "not found" | "No such file or directory" | "grep:"&lt;BR /&gt;       | "WARNING" | "FAILED" | "Permission denied"' $BACKUP_LOG ]&lt;BR /&gt;         then&lt;BR /&gt;           $MAIL -s "$SUBJECT" $MAILTO &amp;lt; $BACKUP_LOG&lt;BR /&gt;     fi&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jan 2004 17:16:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174460#M161746</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2004-01-26T17:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174461#M161747</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am not able to test but I think that if you replace the grep whit an egrep you are close.&lt;BR /&gt;&lt;BR /&gt;Gideon&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jan 2004 17:21:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174461#M161747</guid>
      <dc:creator>G. Vrijhoeven</dc:creator>
      <dc:date>2004-01-26T17:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174462#M161748</link>
      <description>I have also tried with egrep...</description>
      <pubDate>Mon, 26 Jan 2004 17:22:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174462#M161748</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2004-01-26T17:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174463#M161749</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;If you would like to grep multiple lines, then you would need to use "-E", extended regular expressions. For ex.,&lt;BR /&gt;&lt;BR /&gt;grep -E -i 'already exists|parameter not set' $BACKUP_LOG&lt;BR /&gt;&lt;BR /&gt;etc&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jan 2004 17:26:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174463#M161749</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-01-26T17:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174464#M161750</link>
      <description>Hi again,&lt;BR /&gt;&lt;BR /&gt;Sorrie but i can not this but:&lt;BR /&gt;&lt;BR /&gt;....&lt;BR /&gt;if [ `egrep -qi 'already exits" | "parameter not set" | "find: cannot get"&lt;BR /&gt;| "not found" | "No such file or directory" | "grep:"&lt;BR /&gt;| "WARNING" | "FAILED" | "Permission denied"'` ] then&lt;BR /&gt;....&lt;BR /&gt;etc&lt;BR /&gt;&lt;BR /&gt;Gideon</description>
      <pubDate>Mon, 26 Jan 2004 17:28:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174464#M161750</guid>
      <dc:creator>G. Vrijhoeven</dc:creator>
      <dc:date>2004-01-26T17:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174465#M161751</link>
      <description>Tried with -E&lt;BR /&gt;&lt;BR /&gt;if [ `grep -i` '"..."|"..."' file ...&lt;BR /&gt;&lt;BR /&gt;usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...&lt;BR /&gt;        [-f pattern_file...] [file...]&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jan 2004 17:29:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174465#M161751</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2004-01-26T17:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174466#M161752</link>
      <description>I would change up your script to something like:&lt;BR /&gt;&lt;BR /&gt;if [ -f $BACKUP_LOG ]&lt;BR /&gt;then&lt;BR /&gt;VAR1=$(grep -q -i -e "already exists" -e "parameter not set" -e "find: cannot get" -e "not found" -e "No such file or directory" -e "grep:" -e "WARNING" -e "FAILED" -e "Permission Denied" $BACKUP_LOG)&lt;BR /&gt;if [ $? = 0 ]&lt;BR /&gt;then&lt;BR /&gt;$MAIL -s "$SUBJECT" $MAILTO &amp;lt; $BACKUP_LOG&lt;BR /&gt;fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jan 2004 17:30:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174466#M161752</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2004-01-26T17:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174467#M161753</link>
      <description>You need to use "-e" to specify multiple patterns. I would also use -q since all you care about is the status. If 0 then at least one of the patterns was found:&lt;BR /&gt;&lt;BR /&gt;if [[ -f ${BACKUP_LOG} ]]&lt;BR /&gt;then&lt;BR /&gt;  grep -i -E -q -e "already exits" -e "parameter not set" -e "find: cannot get"&lt;BR /&gt;-e "not found" -e "No such file or directory" -e "grep:"&lt;BR /&gt;-e "WARNING" -e "FAILED" -e "Permission denied" ${BACKUP_LOG}&lt;BR /&gt;STAT=${?}&lt;BR /&gt;if [[ ${STAT} -eq 0 ]]&lt;BR /&gt;then&lt;BR /&gt;${MAIL} -s "${SUBJECT}" ${MAILTO} &amp;lt; ${BACKUP_LOG}&lt;BR /&gt;fi&lt;BR /&gt;fi &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jan 2004 17:30:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174467#M161753</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-01-26T17:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174468#M161754</link>
      <description>Simple script to do this.&lt;BR /&gt;&lt;BR /&gt;BACKUP_LOG=/tmp/filename&lt;BR /&gt;if [ -f $BACKUP_LOG ]; then&lt;BR /&gt;grep -i "already exists"|"parameter not set"|"find:cannot get"|"WARNING"| $BACKUP_LOG&lt;BR /&gt;if {$? = 0 ]; then&lt;BR /&gt;SUBJECT="Error found"&lt;BR /&gt;email="admin@test.com"&lt;BR /&gt;mailx -s"$SUBJECT" $email&amp;lt;&lt;EOF&gt;&lt;/EOF&gt;"Errors have been found in the file $BACKUP_LOG"&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Let us know if this helps..&lt;BR /&gt;&lt;BR /&gt;Anil</description>
      <pubDate>Mon, 26 Jan 2004 17:49:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174468#M161754</guid>
      <dc:creator>Anil C. Sedha</dc:creator>
      <dc:date>2004-01-26T17:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174469#M161755</link>
      <description>I am still having problems, I revamped my script because I like the way you STAT=${?}&lt;BR /&gt;&lt;BR /&gt;But now I get an error...&lt;BR /&gt;/home/ac/scripts/backup/d2t_archbu.sh[54]: -e:  not found.&lt;BR /&gt;/home/ac/scripts/backup/d2t_archbu.sh[55]: -e:  not found.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if [[ -f $BACKUP_LOG ]]&lt;BR /&gt;then&lt;BR /&gt;     grep -i -E -q -e  "already exits" -e "parameter not set" -e "find: cannot get"&lt;BR /&gt;       -e "not found" -e "No such file or directory" -e "grep:"&lt;BR /&gt;       -e "WARNING" -e "FAILED" -e "Permission denied" $BACKUP_LOG&lt;BR /&gt;     STAT=${?}&lt;BR /&gt;        if [[ ${STAT} -eq 0 ]]&lt;BR /&gt;        then&lt;BR /&gt;       $MAIL -s "$SUBJECT" $MAILTO &amp;lt; $BACKUP_LOG&lt;BR /&gt;        fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jan 2004 17:53:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174469#M161755</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2004-01-26T17:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174470#M161756</link>
      <description>Your whole grep statement with all the '-e' MUST all be one long line.</description>
      <pubDate>Mon, 26 Jan 2004 17:55:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174470#M161756</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2004-01-26T17:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174471#M161757</link>
      <description>In the script i mentioned, i forgot to end it with 2 fi's on seperate line..  pls try using that.</description>
      <pubDate>Mon, 26 Jan 2004 18:00:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174471#M161757</guid>
      <dc:creator>Anil C. Sedha</dc:creator>
      <dc:date>2004-01-26T18:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174472#M161758</link>
      <description>or you can use a file&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;if [ -f $BACKUP_LOG ]; then&lt;BR /&gt;cat &amp;gt;grep.pat &amp;lt;&lt;EOG&gt;&lt;/EOG&gt;already exits&lt;BR /&gt;parameter not set&lt;BR /&gt;find: cannot get&lt;BR /&gt;not found&lt;BR /&gt;No such file or directory&lt;BR /&gt;grep:&lt;BR /&gt;WARNING&lt;BR /&gt;FAILED&lt;BR /&gt;Permission denied&lt;BR /&gt;EOG&lt;BR /&gt;if [ `grep -i -f grep.pat $BACKUP_LOG` ]; then&lt;BR /&gt;$MAIL -s "$SUBJECT" $MAILTO &amp;lt; $BACKUP_LOG&lt;BR /&gt;fi&lt;BR /&gt;rm grep.pat&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Easy to read, easy to maintain, easy to extend&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Mon, 26 Jan 2004 18:00:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174472#M161758</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-01-26T18:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174473#M161759</link>
      <description>The entire grep command must be one line or continued with the "\" as the LAST character on each line to be combined.&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jan 2004 18:04:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174473#M161759</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-01-26T18:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174474#M161760</link>
      <description>In response to your "Tried with -E"&lt;BR /&gt;&lt;BR /&gt;$cat data&lt;BR /&gt;already exist bla bla&lt;BR /&gt;parameter not set yada yada&lt;BR /&gt;find: cannot get this is a test line&lt;BR /&gt;No such file or directory ofcourse there is no such file or directory&lt;BR /&gt;$grep -E -i 'already exist|parameter not set|find: cannot' data&lt;BR /&gt;already exist bla bla&lt;BR /&gt;parameter not set yada yada&lt;BR /&gt;find: cannot get this is a test line&lt;BR /&gt;&lt;BR /&gt;So, it should have worked if you put everything in one line as mentioned by others.&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jan 2004 18:15:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174474#M161760</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-01-26T18:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174475#M161761</link>
      <description>As mentioned, one line is necessary for the grep to work. The HP Forums uses a proportional font and breaks the lines up so they are difficult to interpret. I have taken the approach that long lines are always a problem (cut-n-paste, folded by editors, etc) so i keep them short by escaping the end-of-line and putting multiple options on separate lines. This has the added effect of making the actual command much more readable:&lt;BR /&gt; &lt;BR /&gt;if [ grep -i &lt;BR /&gt; -e "already exits" \&lt;BR /&gt; -e "parameter not set" \&lt;BR /&gt; -e "find: cannot get" \&lt;BR /&gt; -e "not found" \&lt;BR /&gt; -e "No such file or directory" \&lt;BR /&gt; -e "grep:" \&lt;BR /&gt; -e "WARNING" \&lt;BR /&gt; -e "FAILED" \&lt;BR /&gt; -e "Permission denied" \&lt;BR /&gt; $BACKUP_LOG ]&lt;BR /&gt;then&lt;BR /&gt;...&lt;BR /&gt;fi&lt;BR /&gt; &lt;BR /&gt;Note that -E (or egrep) brings a lot of extra parsing code into play for extended regular expressions. Usually the -e approach is faster and easier to read. You might want to change the words WARNING and FAILED to WARN and FAIL so grep will pickup both forms. And I would add ERROR and CRITICAL to your list just in case.</description>
      <pubDate>Mon, 26 Jan 2004 18:31:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174475#M161761</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2004-01-26T18:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: grep in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174476#M161762</link>
      <description>Note that the first line of my example is missing a trailing \ at the end. The \ removes the special meaning of the end-of-line and makes all the lines look like one.</description>
      <pubDate>Mon, 26 Jan 2004 18:33:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-in-script/m-p/3174476#M161762</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2004-01-26T18:33:06Z</dc:date>
    </item>
  </channel>
</rss>

