LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-11-2012, 09:42 AM   #1
Vegan
Member
 
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114
Blog Entries: 2

Rep: Reputation: 10
Mail Sending Multiple Copies


I have Logrotate set up to rotate my log files daily.
Under one log file i have it set to email me the contents of the file prior to rotating.
The Problem is, i am getting between 13 & 21 email. Same copies of the same email.
Here is the portion of my logrotate script that emails.
The mail portion of logrotate, i could not get to send me the contents of the log, which is why i am going in a round about way

Code:
/var/log/auth.log {
	prerotate
		
		cat /var/log/auth.log >> /home/vegan/temp.txt
		ssmtp vegan6@gmail.com < /home/vegan/temp.txt
		rm /home/vegan/temp.txt
	endscript
	}
Any help is greatly appreciated.
 
Old 08-11-2012, 05:13 PM   #2
floppy_stuttgart
Senior Member
 
Registered: Nov 2010
Location: EU mainland
Distribution: Debian like
Posts: 1,181
Blog Entries: 5

Rep: Reputation: 107Reputation: 107
can you put a wait 10s (or more) after the "cat /var/log/auth.log >> /home/vegan/temp.txt" ?
My non verified impression / idea /feeling is: cat is started as a spawn and the ssmtp is repeated as long the file is not closed by cat.
 
1 members found this post helpful.
Old 08-11-2012, 05:25 PM   #3
Vegan
Member
 
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114

Original Poster
Blog Entries: 2

Rep: Reputation: 10
That is an excellent idea. I couldn't think of why it kept sending. Ill add in a wait and check in the morning. The cron job runs at 300 mst. Ill post back with results.
 
Old 08-12-2012, 09:21 AM   #4
Vegan
Member
 
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114

Original Poster
Blog Entries: 2

Rep: Reputation: 10
No such luck Put in a wait 13s after the cat, and still had 21 emails sent to me.
 
Old 08-13-2012, 05:27 AM   #5
floppy_stuttgart
Senior Member
 
Registered: Nov 2010
Location: EU mainland
Distribution: Debian like
Posts: 1,181
Blog Entries: 5

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by Vegan View Post
No such luck Put in a wait 13s after the cat, and still had 21 emails sent to me.
all mails has 100% the same content? curious.
 
Old 08-13-2012, 08:09 AM   #6
Vegan
Member
 
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114

Original Poster
Blog Entries: 2

Rep: Reputation: 10
Quote:
Originally Posted by floppy_stuttgart View Post
all mails has 100% the same content? curious.
From what i have seen, yes they have
 
Old 08-13-2012, 12:38 PM   #7
floppy_stuttgart
Senior Member
 
Registered: Nov 2010
Location: EU mainland
Distribution: Debian like
Posts: 1,181
Blog Entries: 5

Rep: Reputation: 107Reputation: 107
use

mail vegan6@gmail.com < /home/vegan/temp.txt

?

see https://wiki.archlinux.org/index.php/SSMTP

Last edited by floppy_stuttgart; 08-13-2012 at 01:42 PM.
 
1 members found this post helpful.
Old 08-14-2012, 08:26 AM   #8
Vegan
Member
 
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114

Original Poster
Blog Entries: 2

Rep: Reputation: 10
Quote:
Originally Posted by floppy_stuttgart View Post
use

mail vegan6@gmail.com < /home/vegan/temp.txt

?

see https://wiki.archlinux.org/index.php/SSMTP
Will be trying this tonight. Tried last night, but ended up with a syntax error
 
Old 08-15-2012, 12:07 PM   #9
floppy_stuttgart
Senior Member
 
Registered: Nov 2010
Location: EU mainland
Distribution: Debian like
Posts: 1,181
Blog Entries: 5

Rep: Reputation: 107Reputation: 107
can you use "mutt" instead of ssmtp? I m personally trying to use it with tinycorelinux. it seems to act like "mail".
what distro it is? (ask them how to configure ssmtp)
 
Old 08-15-2012, 12:25 PM   #10
Vegan
Member
 
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114

Original Poster
Blog Entries: 2

Rep: Reputation: 10
It seems as though changing the ssmtp to mail may have fixed it.

Will know for sure when the log file is big enough to rotate.
Before i was getting mass emails even if it didn't rotate.

Mutt was going to be my next option, although i already have everything integrated with ssmtp.

May start looking into it though.

Thank you!
 
Old 08-15-2012, 12:38 PM   #11
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by Vegan View Post
I have Logrotate set up to rotate my log files daily.
......
The mail portion of logrotate, i could not get to send me the contents of the log, which is why i am going in a round about way

Code:
/var/log/auth.log {
	prerotate
		
		cat /var/log/auth.log >> /home/vegan/temp.txt
		ssmtp vegan6@gmail.com < /home/vegan/temp.txt
		rm /home/vegan/temp.txt
	endscript
	}
Any help is greatly appreciated.
Although I don't know if it will be 100% successful but if you would use the "&&" operator in script command (bash ?) , that would mean: when 1st command finishes successfully start 2nd command etc...
Code:
		cat /var/log/auth.log >> /home/vegan/temp.txt
		ssmtp vegan6@gmail.com < /home/vegan/temp.txt
		rm /home/vegan/temp.txt

would be:
	cat /var/log/auth.log >> /home/vegan/temp.txt &&  mail vegan6@gmail.com < /home/vegan/temp.txt  && 	rm /home/vegan/temp.txt

Last edited by lithos; 08-15-2012 at 12:40 PM.
 
1 members found this post helpful.
Old 08-17-2012, 08:15 AM   #12
Vegan
Member
 
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114

Original Poster
Blog Entries: 2

Rep: Reputation: 10
switching ssmtp to mail did not work (mail is a separate command in logrotate)
appending && to the end of each line and will test in the morning.
 
Old 08-17-2012, 04:44 PM   #13
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
I'm wondering if I'm missing something here, just curious why you're using >> to append to /home/vegan/temp.txt as opposed to > when you remove /home/vegan/temp.txt anyway? Is there something outside the prerotate script that has already put something into /home/vegan/temp.txt ?

I know this is strange idea, but it's a strange situation. Is it possible logrotate is doing something strange like looping, looking at the access time of /var/log/auth.log rather than the mod time?

I understand that what I'm about to suggest, would not mail you the contents of /var/log/auth.log
I'm only suggesting this as a test to determine how logrotate is handling things.
If you change your prerotate entry to this:

Code:
	prerotate
		
		echo test > /home/vegan/temp.txt
		ssmtp vegan6@gmail.com < /home/vegan/temp.txt
		rm /home/vegan/temp.txt
	endscript
so that you don't access /var/log/auth.log from the prerotate script, and don't append to /home/vegan/temp.txt do you still get multiple E-Mail messages?

Also, have you tried turning the debug output on for logrotate, to see if there's anything helpful in that output?
 
1 members found this post helpful.
Old 08-18-2012, 09:14 AM   #14
Vegan
Member
 
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114

Original Poster
Blog Entries: 2

Rep: Reputation: 10
Quote:
Originally Posted by kakaka View Post
I'm wondering if I'm missing something here, just curious why you're using >> to append to /home/vegan/temp.txt as opposed to > when you remove /home/vegan/temp.txt anyway? Is there something outside the prerotate script that has already put something into /home/vegan/temp.txt ?

I know this is strange idea, but it's a strange situation. Is it possible logrotate is doing something strange like looping, looking at the access time of /var/log/auth.log rather than the mod time?

I understand that what I'm about to suggest, would not mail you the contents of /var/log/auth.log
I'm only suggesting this as a test to determine how logrotate is handling things.
If you change your prerotate entry to this:

Code:
	prerotate
		
		echo test > /home/vegan/temp.txt
		ssmtp vegan6@gmail.com < /home/vegan/temp.txt
		rm /home/vegan/temp.txt
	endscript
so that you don't access /var/log/auth.log from the prerotate script, and don't append to /home/vegan/temp.txt do you still get multiple E-Mail messages?

Also, have you tried turning the debug output on for logrotate, to see if there's anything helpful in that output?
Excellent suggestions in here! Thank you!
I hadn't even thought of running debug mode... kept thinking of this as a cron job and not a logrotate script. going to be getting a lot more testing done now

Taking your ideas into account i started looking through the man page again and found this

sharedscripts
Normally, prerotate and postrotate scripts are run for each log which is rotated and the absolute path to the log file is passed as first argument to the script. That means a single script may be run multiple times for log file entries which match multiple files (such as the /var/log/news/* example). If sharedscripts is specified, the scripts are only run once, no matter how many logs match the wildcarded pattern, and whole pattern is passed to them. However, if none of the logs in the pattern require rotating, the scripts will not be run at all. If the scripts exit with error, the remaining actions will not be executed for any logs. This option overrides the nosharedscripts option and implies create option.


I am thinking that this may have something to do with it. since nosharedscripts is default and will run multiple times .

I will do some testing and be back with my results!

Last edited by Vegan; 08-18-2012 at 09:16 AM.
 
Old 08-18-2012, 12:37 PM   #15
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
sharedscripts was the first consideration I thought of when I heard about the problem. But, since you are not using a wildcard in your pattern, AFAIK, if the logrotate you are using is implemented properly, it should not be an issue. Of course, it may not be implemented properly!
 
1 members found this post helpful.
  


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
mail program sending multiple emails countrydj Linux - General 2 09-02-2011 11:24 AM
Multiple mail sending server jindalarpan Linux - Server 8 06-26-2010 01:46 PM
sendmail is sending unnecessary multiple copies of emails from php form swg1cor14 Linux - Server 1 01-07-2010 08:25 AM
Qmail sending Multiple copies of Email fedoraman Linux - Server 1 04-15-2008 01:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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