Avatar of gswitz
gswitz
 asked on

Easy REGEXP question #2

I am applying this regexp pattern
File Not Found|LRM\-|Error|Ora\-|SP2\-|FAIL|RC\s*=\s*-?[123456789]+

to look for errors in a log using this function...

Send_Mail_OnError()
{
  #For each line in regex_patterns.txt file,
  #the regular expression-like will fire on the file $error_log
  #if any line returns true, then we will step into the if...
  #Be advised!! Passing a null value in $error_log causes an indefinite hang.
  if egrep -i -s -f $root_dir/regex_patterns.txt $error_log; then
    #For each email address in $emaillist, send and email...
    Send_Mail
  fi
}

This works well for all cases except a single job which sometimes returns the following two lines within the file...

0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.

So I think I want to use the results from an exclusionary egrep call first... maybe something like this...


Send_Mail_OnError()
{
  #For each line in regex_patterns.txt file,
  #the regular expression-like will fire on the file $error_log
  #if any line returns true, then we will step into the if...
  #Be advised!! Passing a null value in $error_log causes an indefinite hang.
  if egrep -i -s -f $root_dir/regex_patterns.txt [egrep -v '0 Rows not loaded due to data errors\.|0 Rows not loaded because all WHEN clauses were failed\.' $error_log]; then
    #For each email address in $emaillist, send and email...
    Send_Mail
  fi
}

Could someone help me with this syntax? Am I on the right track?

Thanks!!

G
Regular ExpressionsUnix OSLinux

Avatar of undefined
Last Comment
gswitz

8/22/2022 - Mon
ThomasMcA2

I would grep -v first, then pipe that to grep -i -s:

if grep -v ... | grep -i -s; then

Open in new window

gswitz

ASKER
Sorry for needing hand holding...

Could you give me the exact syntax based in my posted code?
ASKER CERTIFIED SOLUTION
Gerwin Jansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
gswitz

ASKER
Works like a charm! Thanks!!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes