Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bash Script Question

Status
Not open for further replies.
Aug 27, 2001
502
US
In case it matters, I'm using Fedora Core 2.

I have a script which runs nightly and parses my Dansguardian and Squid log files looking for "DENIED". For each line which contains the searched text, that line is added to a "denied.log" file. At the end of the script, it emails me the log file.

I'd like to only get the email if there is something to report.

Here are the lines which do the work for the Dansguardian portion:

Code:
more /usr/local/dansguardian/access.log | grep *DENIED* > /usr/local/dansguardian/denied.log

cat /usr/local/dansguardian/denied.log | /usr/bin/Mail -s "Dansguardian Violation Log" me@mydomain.com

How can I check that the file size is greater than zero before I send the email?

Thanks,
Ron

“If you are irritated by every rub, how will you be polished?”
~ Mevlana Rumi


Do you live in Michigan? Join us in the Tek-Tips in Michigan forum.
 
Nevermind. I think I figured it out.

Code:
more /usr/local/dansguardian/access.log |grep *DENIED* > /usr/local/dansguardian/denied.log

if [ -s /usr/local/dansguardian/denied.log ]; then

cat /usr/local/dansguardian/denied.log | /usr/bin/Mail -s "Dansguardian Violation Log" me@mydomain.com

fi
Right?

Ron

“If you are irritated by every rub, how will you be polished?”
~ Mevlana Rumi


Do you live in Michigan? Join us in the Tek-Tips in Michigan forum.
 
Code:
#!/bin/bash -p
DGDIR=/usr/local/dansguardian

grep '*DENIED*' $DGDIR/access.log > $DGDIR/denied.log
if [ $? != 0 ]
then
  /usr/bin/Mail -s "DG Violations" me@mydomain.com < $DGDIR/denied.log
fi

And for your homework, figure out what each change did (other than using $DGDIR, that was just to keep the lines from wrapping).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top