LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-29-2005, 05:29 AM   #1
ladyath
LQ Newbie
 
Registered: Sep 2004
Posts: 10

Rep: Reputation: 0
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!
 
Old 03-29-2005, 07:36 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,433

Rep: Reputation: 203Reputation: 203Reputation: 203
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.
 
Old 03-29-2005, 07:49 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,433

Rep: Reputation: 203Reputation: 203Reputation: 203
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!?!?!
 
Old 03-30-2005, 12:51 AM   #4
ladyath
LQ Newbie
 
Registered: Sep 2004
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks a lot This will definately work for me
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
crontab vs cron.daily ? SheldonPlankton Linux - Newbie 1 07-16-2004 01:10 PM
cron.daily error gjmwalsh Mandriva 2 10-29-2003 03:12 PM
Mail daily logs through shell scripts klnasveschuk Linux - Software 0 08-07-2003 06:02 AM
cron.daily MrJoshua Linux - General 2 03-19-2003 01:09 PM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 03:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration