Off-Topic > Off-Topic - Tiny Tux's Corner
RegEx to find error but exclude no error
(1/1)
remus:
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: ---# 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
--- End code ---
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 :)
curaga:
grep -vi "no error" $LOGFILE | grep -ciE ...
remus:
thanks for the input curaga, its still finding my excluded string though.
Here's my update
--- Code: ---# 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
--- End code ---
Did I make a simple syntax error maybe ?
curaga:
Yes, remove the second $LOGFILE. The second grep should grep the pipe.
remus:
That nailed it !
Thanks curaga :)
Navigation
[0] Message Index
Go to full version