LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 02-21-2010, 01:52 AM   #1
Skillz
Member
 
Registered: Sep 2007
Posts: 252

Rep: Reputation: 32
Emailing the log entries daily...


Alright, I want to email myself the daily log entries of the /etc/messages log file. What I mean is, for all new lines created on Feb 21, I want them emailed to me on the 22nd. For all new log entries created on Feb 20, I want them emailed to me on Feb 21. Etc...

This is what I have come up with so far.

less messages | grep "Feb 20" | mail -s "Messages Log Output" l-bsdsadasdsad@gmail.com

(I used my real email address in the command line, don't want to post it here for the spammers)

Now this does exactly what I want however I want this done automatically every day. Now I know I can set this up in a cronjob to run at 00:00 every day, but my problem is how do I tell the script to look for "Current Date" in that format? (Three letter month [space] day) I also noticed that if it's a single digit day, then it's (Three letter month [space][space] day)

I also realize that these daily logs could get rather large, especially if a lot was going on that day with the FTP.
 
Old 02-21-2010, 02:00 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
You can format the output of date, and embed the output into your grep, eg
Code:
... | grep "$(date '+%b %e')" | ...
(of course, that is the current date, not the previous one; you could run an earlier cronjob to squirrel away the previous day's date instead)

Last edited by neonsignal; 02-21-2010 at 02:15 AM.
 
1 members found this post helpful.
Old 02-21-2010, 02:13 AM   #3
Skillz
Member
 
Registered: Sep 2007
Posts: 252

Original Poster
Rep: Reputation: 32
Would it even be possible to do the previous day with the date command? Is there a "yesterday" command within' the date command? Hmm..
 
Old 02-21-2010, 02:15 AM   #4
Skillz
Member
 
Registered: Sep 2007
Posts: 252

Original Poster
Rep: Reputation: 32
I got it.

less messages | grep "$(date --date="yesterday" '+%b %e')" | mail -s "Messages Log Output" l-bsdsadasdsad@gmail.com

Last edited by Skillz; 02-21-2010 at 02:16 AM.
 
Old 02-21-2010, 02:33 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
BTW, instead of having to wade through all messages manually, how about using Logwatch instead? Logwatch can process all sorts of system and daemon logs, comes with support for several services including FTP daemons out of the box, doesn't need much configuration and can email you alerts daily.
 
Old 02-21-2010, 02:36 AM   #6
Skillz
Member
 
Registered: Sep 2007
Posts: 252

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by unSpawn View Post
BTW, instead of having to wade through all messages manually, how about using Logwatch instead? Logwatch can process all sorts of system and daemon logs, comes with support for several services including FTP daemons out of the box, doesn't need much configuration and can email you alerts daily.
Logwatch? Where can I find it?
 
Old 02-21-2010, 02:44 AM   #7
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
http://www.logwatch.org/
 
Old 02-21-2010, 02:47 AM   #8
Skillz
Member
 
Registered: Sep 2007
Posts: 252

Original Poster
Rep: Reputation: 32
Google is my friend, I got it installed I think. The README says it should work on it's own, I simply ran the install_logwatch.sh file and it did some stuff, I then changed the default conf file to mail it to my email address, instead of root.

Does it start itself automatically, I don't need to do anything else?

I ran the command

logwatch mailto myemail@email.com

Few seconds later it completed and I got a new email. Will it do this all the time without me telling it to?

Last edited by Skillz; 02-21-2010 at 02:51 AM.
 
Old 02-21-2010, 03:20 AM   #9
Skillz
Member
 
Registered: Sep 2007
Posts: 252

Original Poster
Rep: Reputation: 32
LogWatch is freaking awesome, wish I could have found this sooner!!!

Still not sure if this will run every day though or if I'll have to run some kind of cronjob to execute it each day.
 
Old 02-21-2010, 03:21 AM   #10
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Sounds like you did it. If you don't get the emails make sure it runs via cron
 
Old 02-21-2010, 03:22 AM   #11
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
The install script may have put in a cron entry for you. Check it out;
 
Old 02-21-2010, 03:25 AM   #12
Skillz
Member
 
Registered: Sep 2007
Posts: 252

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by micxz View Post
The install script may have put in a cron entry for you. Check it out;
Very good point. I looked at what the install script did and found this entry.

ln -s /usr/share/logwatch/scripts/logwatch.pl /etc/cron.daily/0logwatch

So I am thinking it covered that for me.
 
Old 09-02-2012, 09:45 PM   #13
Skillz
Member
 
Registered: Sep 2007
Posts: 252

Original Poster
Rep: Reputation: 32
Alright, I want to email myself the daily log entries of the /etc/messages log file. What I mean is, for all new lines created on Feb 21, I want them emailed to me on the 22nd. For all new log entries created on Feb 20, I want them emailed to me on Feb 21. Etc...

This is what I have come up with so far.

less /var/log/messages | grep "$(date --date="yesterday" '+%b %e')" | mail -s "Messages Log Output" myemail@gmail.com

(I used my real email address in the command line, don't want to post it here for the spammers)

Now this does exactly what I want however I want this done automatically every day. Now I know I can set this up in a cronjob to run at 00:00 every day, but my problem is how do I tell the script to look for "Current Date" in that format? (Three letter month [space] day) I also noticed that if it's a single digit day, then it's (Three letter month [space][space] day)

I also realize that these daily logs could get rather large, especially if a lot was going on that day with the FTP.

This no longer works. I've discovered that less /var/log/messages still displays the output, however then I use grep "$(date --date="yesterday" '+%b %e')" nothing is shown. Message is null. I'm guessing "yesterday" is no longer valid. How can I get this to work now?
 
Old 09-02-2012, 09:52 PM   #14
Skillz
Member
 
Registered: Sep 2007
Posts: 252

Original Poster
Rep: Reputation: 32
Well I figured out it's because /var/log/messages doesn't contain anything from Sep 1, it's been rotated to messages.1. Sigh
 
  


Reply



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
Strange log entries in apache log under debian... hacking tentative ? strelok Linux - Security 4 11-11-2009 06:55 AM
Can Samhain log my entries in /var/log/secure and /var/log/mesage to a central server abefroman Linux - Software 2 04-13-2008 04:13 PM
Emailing log files and system mail... AnRkey Linux - Security 6 11-10-2005 06:17 PM
I need the syntax for emailing a log file. Pcghost Linux - General 14 07-22-2003 11:37 AM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 02:30 PM

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

All times are GMT -5. The time now is 04:39 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
Open Source Consulting | Domain Registration