February 22

Grep a log file and send output to mail

This is a small script that looks for a string in a log file and then the string is found, sents by mail the output

-This example is for Smoothwall, in which i run Guardian Active response and i wanted to know who is blocked

-Place it in your rc.local, reboot and check your mailbox




EMAILSUBJECT="Guardian On Firewall "

##Select you log file
#tail -f /var/log/messages | while read LINE
tail -f /var/log/guardian/guardian.log | while read LINE
#Select the string
if [ `echo $LINE | grep -c "blocked"` -gt 0 ]
# if [ `echo $LINE | grep -c "eth"` -gt 0 ]

echo "Guardian actions:" > $MESSAGEBODY
#Insert some text before the output
# echo "Guardian done it again !" >> $MESSAGEBODY
#Here i use sendEmail from Smoothwall, you can use you own sendmail/mail commands
sendEmail -f -u "$EMAILSUBJECT" -t -s smtp.gmail.com:587 -xu [email protected] -xp password < $MESSAGEBODY
# fi

Tags: ,
Copyright © 1998. All rights reserved.

Posted February 22, 2014 by RaNd in category "/etc/config

Select comment form

Loading Facebook Comments ...

Leave a Reply

Your email address will not be published. Required fields are marked *

16 − fourteen =