LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   logrotate doesnt not rotate properly (https://www.linuxquestions.org/questions/linux-software-2/logrotate-doesnt-not-rotate-properly-734698/)

Niceman2005 06-22-2009 02:58 AM

logrotate doesnt not rotate properly
 
Dear friends,

I have the following logrotate configuration in /etc/logrotate.d/maillog

/var/log/maillog {
daily
rotate 5
}

, so i did a debug run with the following command:

1st rotate) logrotate -f -s -d /etc/logrotate.d/maillog


The first rotate works fine with the following results in /var/log:
maillog.1 (note: original maillog is missing)

2nd rotate) logrotate -f -s -d /etc/logrotate.d/maillog

The error says:
error: stat of /var/log/maillog failed: No such file or directory


apparently because the original maillog file has been replaced with maillog.1.

but based on the http://www.forteach.net/os/sysadmin/35751.html
during a rotate, the original maillog will be replaced by maillog.1 by the original does not remove.

so my understanding the content of /var/log folder should be:
before rotate: maillog
first rotate: maillog maillog.1
2nd rotate: maillog maillog.2 maillog.3
3rd rotate maillog maillog.2 maillog.3 maillog.4
and on and on.....till rotate no 5 it gets roll over again.

However my configuration above now is working incrrectly as below:
before rotate: maillog
first rotate: maillog.1
2nd rotate: failed because "error: stat of /var/log/maillog failed: No such file or directory"

anyone knows what went wrong in my configuration?
All i want to achieve is a rotation on a daily basis, so that i have each log file containning only 1 day of log records, day by day, easy for analysis. Rotate for 7 days then replace again.
I couldnt achive it because of the above problem, hope anyone can point out my mistake.

thanks

jomen 06-22-2009 03:56 AM

There is probably nothing wrong.
The log-files are created when written to.
You removed the logfile by rotating it.
If nothing was written to the maillog before you tried to rotate it again - it is not there.

man logrotate

There are options like:
missingok
compress
notifyempty
postrotate - which can take care of i.e. reloading the logger after the logfiles have been rotated.
My (the default) config for syslog-ng looks like this:
Code:

/var/log/messages {
    missingok
    sharedscripts
    postrotate
        /etc/init.d/syslog-ng reload > /dev/null 2>&1 || true
    endscript
}

HTH

vap16oct1984 06-22-2009 04:26 AM

yea thats true i hope its work.


All times are GMT -5. The time now is 01:33 AM.