Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

For logrotate I have a cron task that runs hourly.
In logrotate.conf there's the directive "daily". But the log files are rotated hourly, not daily.
Why does it happen? What's this directive for? I thought that these time-related directives are for rotating more seldom than the tool executed.

$ cat /opt/etc/logrotate.conf
compress
/opt/var/log/dir300.log {
        daily
        rotate 29
        postrotate
                killall -HUP syslog-ng
        endscript
}

.

$ grep logrotate /opt/etc/crontab 
50 */1 * * * admin /opt/sbin/logrotate -f /opt/etc/logrotate.conf &>/dev/null

$ ls -l dir300.log*
-rw------- 1 admin root 159856 2013-01-08 11:29 dir300.log
-rw------- 1 admin root   6838 2013-01-08 01:50 dir300.log.10.gz
-rw------- 1 admin root     20 2013-01-08 00:50 dir300.log.11.gz
-rw------- 1 admin root    592 2013-01-07 23:50 dir300.log.12.gz
-rw------- 1 admin root    124 2013-01-07 22:50 dir300.log.13.gz
-rw------- 1 admin root     20 2013-01-07 21:50 dir300.log.14.gz
-rw------- 1 admin root     20 2013-01-07 20:50 dir300.log.15.gz
-rw------- 1 admin root    107 2013-01-07 19:50 dir300.log.16.gz
-rw------- 1 admin root     20 2013-01-07 18:50 dir300.log.17.gz
-rw------- 1 admin root     20 2013-01-07 17:50 dir300.log.18.gz
-rw------- 1 admin root     20 2013-01-07 16:50 dir300.log.19.gz
-rw------- 1 admin root  14158 2013-01-08 10:50 dir300.log.1.gz
-rw------- 1 admin root     20 2013-01-07 15:50 dir300.log.20.gz
-rw------- 1 admin root     20 2013-01-07 14:50 dir300.log.21.gz
-rw------- 1 admin root    133 2013-01-07 13:50 dir300.log.22.gz
-rw------- 1 admin root     20 2013-01-07 12:50 dir300.log.23.gz
-rw------- 1 admin root    279 2013-01-07 11:50 dir300.log.24.gz
-rw------- 1 admin root     20 2013-01-07 10:50 dir300.log.25.gz
-rw------- 1 admin root     20 2013-01-07 09:50 dir300.log.26.gz
-rw------- 1 admin root     20 2013-01-07 08:50 dir300.log.27.gz
-rw------- 1 admin root     20 2013-01-07 07:50 dir300.log.28.gz
-rw------- 1 admin root     20 2013-01-07 06:50 dir300.log.29.gz
-rw------- 1 admin root  14236 2013-01-08 09:50 dir300.log.2.gz
-rw------- 1 admin root  14135 2013-01-08 08:50 dir300.log.3.gz
-rw------- 1 admin root  14349 2013-01-08 07:50 dir300.log.4.gz
-rw------- 1 admin root  14396 2013-01-08 06:50 dir300.log.5.gz
-rw------- 1 admin root  14268 2013-01-08 05:50 dir300.log.6.gz
-rw------- 1 admin root  14148 2013-01-08 04:50 dir300.log.7.gz
-rw------- 1 admin root  14347 2013-01-08 03:50 dir300.log.8.gz
-rw------- 1 admin root  14225 2013-01-08 02:50 dir300.log.9.gz

.

$ ipkg list logrotate
logrotate - 3.7.5-2 - Rotates, compresses, removes and mails system log files.
share|improve this question

1 Answer 1

up vote 2 down vote accepted

This is because you are using -f to force log rotation in the cron job command below:

50 */1 * * * admin /opt/sbin/logrotate -f /opt/etc/logrotate.conf &>/dev/null

If you read man logrotate and look at the following paragraph:

-f, --force
Tells logrotate to force the rotation, even if it doesn't think this is necessary. Sometimes this is useful after adding new entries to a logrotate config file, or if old log files have been removed by hand, as the new files will be created, and logging will continue correctly.

This is clear from the created files timestamp. If you look at some files like the following:

-rw------- 1 admin root  14349 2013-01-08 07:50 dir300.log.4.gz
-rw------- 1 admin root  14396 2013-01-08 06:50 dir300.log.5.gz
-rw------- 1 admin root  14268 2013-01-08 05:50 dir300.log.6.gz
-rw------- 1 admin root  14148 2013-01-08 04:50 dir300.log.7.gz
-rw------- 1 admin root  14347 2013-01-08 03:50 dir300.log.8.gz
-rw------- 1 admin root  14225 2013-01-08 02:50 dir300.log.9.gz

You can easily see that each execution of the cron job creates a new file. Again, this is because of the option -f.

share|improve this answer
    
Just ran into this myself. Nice user-hostile software, "-f /some/config/file" is valid syntax but doesn't mean "load this config file". –  Dan Pritts Aug 5 '13 at 17:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.