LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Mailing daily logs via cron? (https://www.linuxquestions.org/questions/linux-general-1/mailing-daily-logs-via-cron-307299/)

ladyath 03-29-2005 04:29 AM

Mailing daily logs via cron?
 
Hi there
I would like to mail the contents of a directory, but not quite sure on the script to do this. What needs to happen:
1) Tar all the files in the directory
2) Mail the tar file
3) Clear the directory

To script this as a daily cron, would this be correct?

Code:

#!/bin/sh
cd /var/logs/snort
tar -cf logs.tar /var/log/snort/*
mail logs.tar myemail@somewhere.com
rm *


What am I missing here?
Thanks!

bigearsbilly 03-29-2005 06:36 AM

Yaaaaargh!
Don't delete the old logs so casually!

don't throw information away, you'll almost always regret it!

Look at man logrotate and rotate and archive your logs

if you want them just in a mail message

cat *.log | mailx -s subject user @ blah.com

if you want an attachment

uuencode logs.tar logs.tar | mailx -s subject user @ blah.com

May work, depending on your MTA set-up at the other end, whether it decodes i think.
(outlook usually works, yahoo doesn't).

Otherwise look up your mailer how to attach a file.
I think mutt -a will send an attachment.

bigearsbilly 03-29-2005 06:49 AM

Advice: don't ever use rm * in a script.
use rm /var/logs/snort/*

Consider this:
Quote:

#!/bin/sh
cd /var/logs/snort fails (no such dir or wrong permissions
tar -cf logs.tar /var/log/snort/* this may fail
mail logs.tar myemail@somewhere.com this may fail
rm * this will NOT fail - but it isn't where you EXPECT it to be!?!?!

ladyath 03-29-2005 11:51 PM

Thanks a lot :) This will definately work for me


All times are GMT -5. The time now is 07:50 AM.