0

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;

2 Answers2

0

uuencode scannedErrors.txt is expecting input - when called with only one option, it treats that option as the name of the file to include in the output, not the name of the file to read. So either do cat scannedErrors.txt | uuencode scannedErrors.txt or uuencode scannedErrors.txt scannedErrors.txt.

I don't necessarily see anything wrong with the grep bit, but it might be useful to put a cat scannedErrors.txt in there to make sure you're finding what you want. You could also do grep ... SystemOut_*[0-9].log rather than the for loop, which would make the -H the default, but you'd probably still need the for loop to rename things, unless you happen to have the rename script available (a perl script that allows creative renaming via regular expressions).

twalberg
  • 59,951
  • 11
  • 89
  • 84
  • neither of these work:( `cat scannedErrors.txt | uuencode ScannedErrors.txt` or `uuencode scannedErrors.txt scannedErrors.txt` edit: Also I did the first part in the loop like that in case new files are created while I'm scanning. This way I don't accidentally name unscanned files as scanned. –  Jun 20 '12 at 14:03
0

try :

{ cat scannedErrors.txt|uuencode scannedErrors.txt;cat Message.txt;}|mailx -s "Scanned Logfile Errors" someone@somewhere.com

because there is a conflict between | and <

Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36
  • This works for attaching the file! Very nice. The only problem is that the Message.txt is no longer the body of the message and I'm not sure how to fix that. I tried again with the `< Message.txt` at the end of the line and it doesn't work so I think you're right in that it's getting confused having both | and –  Jun 20 '12 at 15:11
  • You can concatenate several files, plain text or uuencoded. In the e-mail the uuencoded files will be seen as attachment, the text as the body. – Nahuel Fouilleul Jun 20 '12 at 15:18
  • Well when I include that `cat Message.txt;` in the squiggly brackets the email still sends fine, but it ignores that part completely. Not sure why. –  Jun 20 '12 at 15:23
  • maybe try the cat message before attachment : { cat Message.txt;cat scannedErrors.txt|uuencode scannedErrors.txt;} or a newline is missing { cat scannedErrors.txt|uuencode scannedErrors.txt;echo;cat Message.txt;} – Nahuel Fouilleul Jun 20 '12 at 16:12
  • Argh. When I put `cat Message.txt;` first it ignores that I'm trying to attach scannedErrors.txt and instead includes it in the body. When I try with the `echo;cat Message.txt` it again ignores the Message.txt and only attaches scannedErrors.txt. What on earth... –  Jun 20 '12 at 17:07