Linux - NewbieThis 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.
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.
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
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.
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.
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)
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
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...
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:
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?
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:
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!
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.