I've been trying to figure this out, but not matter what I try it doesn't seem to be working as I want. Basically the things that are missing is that grep is not listing the file names when it finds a match (which is what the -H flag is supposed to do, I think?) and uuencode doesn't seem to want to attach the file in the email. I've tried both uuencode and cat and I'm getting nowhere.
Does anybody have any idea what might be the problem here?
for i in `ls SystemOut_*[0-9].log`; do
grep -inEH '^\[.*(error|exception)' $i >> scannedErrors.txt;
mv "$i" "${i%.log}"_scanned.log;
done
if [[ -s scannedErrors.txt ]]; then
uuencode scannedErrors.txt | mailx -s "Scanned Logfile Errors" someone@somewhere.com < Message.txt;
fi
/bin/rm scannedErrors.txt;