Link to home
Start Free TrialLog in
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
Avatar of ThomasMcA2
ThomasMcA2

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

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

Open in new window

Avatar of gswitz

ASKER

Sorry for needing hand holding...

Could you give me the exact syntax based in my posted code?
ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gswitz

ASKER

Works like a charm! Thanks!!