egrep "[^(javax.mail.MessagingException)+|^(java.net.UnknownHost)+|^
(nested exception is )+]?exception"
kind of works; but not excluding this pattern:
nested exception is:
I'm basically trying to exclude all of this, but catch lines with
"exception"
[17/10/09 18:30:16:524 NZDT] 0000005b SystemErr R
javax.mail.MessagingException: Unknown SMTP host: mailhost;
nested exception is:
java.net.UnknownHostException: mailhost
egrep "^[javax.mail.MessagingException|java.net.UnknownHost|nested
exception is]?exception"
Hope this helps
Casey
Whoops,
Sorry about that.
So, I think that I made two mistakes:
1) made a mistake last time, and read ^ in your regexp as "not"
instead of "Beginning of line", and transferred that to my thinking.
Not sure where that came from.
2) I copied your example, and added two lines with "exception"
before and after, but
it worked by coincidence. Some of the exclusions were based on the
excludes not being at the beginning of the string.
The javax.mail exclusion worked because there wasn't also a
"exception" on the same line (With all lowercase)
It still should have picked up any lines with "exception" though...So
I assume that maybe you want a mixed case exception to be printed?
I would normally cheat with something like this, and use perl. More
verbose...But (to me) easier to read.
(Everything below should be for mixed case "exception"
cat ~/junk | perl -ne '/exception/i and do{ /
javax.mail.MessagingException/ and next;
/java.net.UnknownHost/ and next;
/nested exception is/ and next;
print $_;
}'
Or awk:
cat ~/junk | awk '/java.net.UnknownHost/||/
javax.mail.MessagingException/||/nested exception is/{next;} tolower
($0)~/exception/'
But looking at the egrep man page, I don't see how to get a "not" out
of egrep, except this two stage approach:
cat ~/junk | grep -i exception | egrep -v 'java.net.UnknownHost|
javax.mail.MessagingException|nested exception is'
Hope that actually helps.
Casey
thanks Casey, I was trying to use a standard Nagios plug-in called
check_log which uses grep.
I have switched to a hand-written awk script :)