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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
08-11-2012, 09:42 AM
|
#1
|
Member
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114
Rep:
|
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.
|
|
|
08-11-2012, 05:13 PM
|
#2
|
Senior Member
Registered: Nov 2010
Location: EU mainland
Distribution: Debian like
Posts: 1,181
Rep: 
|
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.
|
08-11-2012, 05:25 PM
|
#3
|
Member
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114
Original Poster
Rep:
|
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.
|
|
|
08-12-2012, 09:21 AM
|
#4
|
Member
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114
Original Poster
Rep:
|
No such luck Put in a wait 13s after the cat, and still had 21 emails sent to me.
|
|
|
08-13-2012, 05:27 AM
|
#5
|
Senior Member
Registered: Nov 2010
Location: EU mainland
Distribution: Debian like
Posts: 1,181
Rep: 
|
Quote:
Originally Posted by Vegan
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.
|
|
|
08-13-2012, 08:09 AM
|
#6
|
Member
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114
Original Poster
Rep:
|
Quote:
Originally Posted by floppy_stuttgart
all mails has 100% the same content? curious.
|
From what i have seen, yes they have
|
|
|
08-13-2012, 12:38 PM
|
#7
|
Senior Member
Registered: Nov 2010
Location: EU mainland
Distribution: Debian like
Posts: 1,181
Rep: 
|
Last edited by floppy_stuttgart; 08-13-2012 at 01:42 PM.
|
|
1 members found this post helpful.
|
08-14-2012, 08:26 AM
|
#8
|
Member
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114
Original Poster
Rep:
|
Quote:
Originally Posted by floppy_stuttgart
|
Will be trying this tonight. Tried last night, but ended up with a syntax error 
|
|
|
08-15-2012, 12:07 PM
|
#9
|
Senior Member
Registered: Nov 2010
Location: EU mainland
Distribution: Debian like
Posts: 1,181
Rep: 
|
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)
|
|
|
08-15-2012, 12:25 PM
|
#10
|
Member
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114
Original Poster
Rep:
|
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!
|
|
|
08-15-2012, 12:38 PM
|
#11
|
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
|
Quote:
Originally Posted by Vegan
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.
|
08-17-2012, 08:15 AM
|
#12
|
Member
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114
Original Poster
Rep:
|
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.
|
|
|
08-17-2012, 04:44 PM
|
#13
|
Member
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705
Rep: 
|
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.
|
08-18-2012, 09:14 AM
|
#14
|
Member
Registered: Aug 2010
Location: Idaho
Distribution: Arch, Ubuntu, Fedora
Posts: 114
Original Poster
Rep:
|
Quote:
Originally Posted by kakaka
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.
|
|
|
08-18-2012, 12:37 PM
|
#15
|
Member
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705
Rep: 
|
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.
|
All times are GMT -5. The time now is 05:04 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|