LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-23-2012, 07:27 PM   #1
killminus9
LQ Newbie
 
Registered: May 2012
Location: Anchorage, AK
Distribution: Debian & Ubuntu primarily
Posts: 2

Rep: Reputation: 0
Logrotate - email log about to be rotated


Hi,

I have been trying for some time now to figure out how to send a log file as an email attachment. I have found how to send files as attachments using mutt: mutt -s "Report Attachment" user@domain.com -a /var/log/rbgaTcp.log < /home/user/messageBody. This string entered in the command line will send the log file located in /var/log, and include the text in the file /home/user/messageBody, in the message body. That is great but what I can't seem to figure out is how to send the log file before it is rotated per the logrotate schedule?

I understand the mail command in the logrotate config file, sample below, will only send mail when a file is rotated out, ie deleted from the system. This is not what I need to do. I have tried putting the mutt string, above, between the firstaction and prerotate options, being sure to end it with endscript. No love. :-( I also put the mutt string in a separate shell script and call that from prerotate, again no love. :-(

Any thoughts are greatly appreciated. Thank you in advance.


SAMPLE FILE: (located in /etc/logrotate.d/configFileName)

/var/log/rbgaInternet.log /var/log/rbgaTcp.log /var/log/rbgaUdp.log {
rotate 53
daily
#firstaction
# mutt -s "Report Attachment" user@domain.com -a /var/log/rbgaTcp.log < /home/user/messageBody
#endscript
prerotate
/home/user/mailLog.sh
endscript
create 666
}

Last edited by killminus9; 05-23-2012 at 07:30 PM.
 
Old 05-23-2012, 08:50 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 18,237

Rep: Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712
Having looked at http://linux.die.net/man/8/logrotate, a couple of things occur to me:

1. you may need to specify the full path to mutt (like you do for cron jobs)
2. that page says that the script will be run by the /bin/sh shell; have you tested using that shell?
3. This happens every time the logs are rotated; it does not depend on actually reaching a limit of 53 and deleting one; its all about the 'current' logfile...
 
Old 05-23-2012, 10:25 PM   #3
killminus9
LQ Newbie
 
Registered: May 2012
Location: Anchorage, AK
Distribution: Debian & Ubuntu primarily
Posts: 2

Original Poster
Rep: Reputation: 0
Sweet! Thank you chrism01! It looks like all that was needed was the full path to mutt. Now every time the log rotates, using logrotate, I get an e-mail with an attachment of the log file just before it is rotated.

thank you!
 
Old 05-24-2012, 02:24 AM   #4
jsaravana87
Member
 
Registered: Aug 2011
Location: Chennai,India
Distribution: Redhat,Centos,Ubuntu,Dedian
Posts: 558
Blog Entries: 5

Rep: Reputation: Disabled
Im using these following script to check my service status, if fails it deliver the error with log

#!/bin/bash

mailid=xxx

SERVICE='httpd'

if ps ax | grep -v grep | grep $SERVICE > /dev/null

then
echo "$SERVICE service running, everything is fine"
else
echo "$SERVICE is not running"
echo "$SERVICE is not running!" | mail -s "$SERVICE down" $mailid1 $mailid2 < /etc/httpd/logs/error_log
fi
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy logrotate question - remove rotated logs after 7 days SmurfGGM Linux - Newbie 1 08-17-2011 06:58 PM
log files not being rotated sang_froid Linux - Server 2 12-11-2009 09:11 AM
Log Rotation using Logrotate keysorsoze Linux - General 4 04-13-2007 02:51 PM
archiving rotated log files tjainsworth Linux - Security 4 07-12-2006 01:00 PM
logrotate error - last rotated in the future ocgltd Fedora 1 10-02-2005 08:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:28 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