Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 07-15-2008, 03:14 PM   #1
LQ Newbie
Registered: Jul 2008
Posts: 2

Rep: Reputation: 0
creating a script to email daily log file

I want to rotate my /var/messages daily and have done that using Webmin. Then I'd like to email the previous days log file to a tech support desk for review and audit entry. I found a few references to creating the email script and one concerning logs, but I want to specifically do the previous days log every single day of the year with no user intervention.

I'd appreciate any help on the matter. Thanks.
Old 07-15-2008, 04:21 PM   #2
Registered: Jan 2008
Location: Israel
Distribution: Kubuntu 13.10
Posts: 134

Rep: Reputation: 34
have you considered using cron?
it can schedule a command(or script) to run every day.
you can use the command:
grep "`date +"%b %d"`" /var/log/messages
to get the messages of the current day.
how you mail it is another story.

btw, most distribution have some tools for doing just what you wanted without writing a script.
it's a common task.
Old 07-15-2008, 04:24 PM   #3
Senior Member
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
A script? Almost ))

E-mail the contents of an ascii logfile in mail body?:

cat file.log | sendmail -oi this@email.address

Is it bzipped? Then first unzip it:

bzcat file.bz2 | sendmail -oi this@email.address

Do you want some header fields to be filled in? Install procmail, and then:

cat file.log | formail -I "From: other@email.address" -I "To: this@email.address" -I "Subject: Log" | sendmail -oi -t

Do you want to send it as an attachment?
Maybe mail or nail can do it. Google a bit, or maybe someone else will help you here.

Last edited by J_Szucs; 07-15-2008 at 04:27 PM.
Old 07-15-2008, 05:30 PM   #4
LQ Guru
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 252Reputation: 252Reputation: 252
Why reinvent the wheel, just install logwatch.
Old 07-15-2008, 09:59 PM   #5
LQ Newbie
Registered: Jul 2008
Posts: 2

Original Poster
Rep: Reputation: 0
thanks. logwatch it is.


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script in cron.daily ;Where does the log go ? jeepescu Linux - General 2 12-03-2007 07:07 PM
Bash script to put log files into single file and email DragonM15 Programming 13 11-08-2007 04:27 AM
Creating an email script? DrDoug Linux - Newbie 10 05-17-2007 07:21 AM
Need a script for daily backup of oracle archive file sathyguy Linux - Newbie 15 01-22-2007 07:49 AM
Daily Status/Security/Info script.. email notification? JakeX Linux - Software 5 07-04-2006 04:27 PM > Forums > Linux Forums > Linux - Server

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

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