Tiny Core Linux

Off-Topic => Off-Topic - Tiny Tux's Corner => Topic started by: remus on July 25, 2017, 09:32:28 PM

Title: RegEx to find error but exclude no error
Post by: remus on July 25, 2017, 09:32:28 PM
Hi all,

I"m trying to put together a error check in my daily file backup bash script.

Here's my error check section

Code: [Select]
# Check the log file for errors
DateTime=$(date +"%d/%m/%Y %H:%M")
ErrorCheck=$(grep -ciE "fail|can't" $LOGFILE)
if [ $ErrorCheck -gt 0 ]
then
 EmailSubject=$ErrorCheck"(s) Errors Detected in DB Backup $DateTime"
else
 EmailSubject="DSS DB Backup $DateTime"
fi

I've noticed that this will specifiy an error in my email subject if it finds "no error" of course.
Can someone suggest a RegEx that will only find error if its not preceeded by "no " ?

Thanks :)
Title: Re: RegEx to find error but exclude no error
Post by: curaga on July 26, 2017, 12:51:34 AM
grep -vi "no error" $LOGFILE | grep -ciE ...
Title: Re: RegEx to find error but exclude no error
Post by: remus on July 26, 2017, 09:14:01 PM
thanks for the input curaga, its still finding my excluded string though.

Here's my update

Code: [Select]
# Check the log file for errors
DateTime=$(date +"%d/%m/%Y %H:%M")
ErrorCheck=$(grep -vi "No errors" $LOGFILE | grep -ciE "error|fail|can't" $LOGFILE)
if [ $ErrorCheck -gt 0 ]
then
 EmailSubject=$ErrorCheck" Errors Detected in DSS DB Backup $DateTime"
else
 EmailSubject="DSS DB Backup $DateTime"
fi

Did I make a simple syntax error maybe ?
Title: Re: RegEx to find error but exclude no error
Post by: curaga on July 27, 2017, 12:46:45 AM
Yes, remove the second $LOGFILE. The second grep should grep the pipe.
Title: Re: RegEx to find error but exclude no error
Post by: remus on July 27, 2017, 08:09:08 PM
That nailed it !
Thanks curaga :)