Rotate Apache logs at Midnight

I have an openSUSE server running 12.1 with Apache which is hosting a few websites using virtual hosting. I have enabled logrotate and my settings look like this:

/var/log/apache2/access_log {
    compress
    rotate 5
    monthly
    maxage 180
    dateext
    notifempty
    missingok
    create 644 root root
    postrotate
     /etc/init.d/apache2 reload
    endscript

}

/var/log/apache2/error_log {
    compress
    rotate 5
    monthlycompress
    dateext
    maxage 365
    rotate 99
    size=+1024k
    notifempty
    missingok
    create 644 root root
    postrotate
     /etc/init.d/apache2 reload
    endscript
    maxage 180
    dateext
    notifempty
    missingok
    create 644 root root
    postrotate
     /etc/init.d/apache2 reload
    endscript

}

My web logs are rotating around 11pm and I need them to rotate at midnight so I can take the logs and inject them into WebTrends. I googled around trying to find a solution to this problem because now I want my logs to rotate on a daily basis with a date/time stamp on the older logs and want to keep 35 days worth of logs before they start falling off the system, get deleted.

If I changed the logrotate to the following the logs should rotate daily but how can I set the midnight time to rotate the logs?

/var/log/apache2/access_log {
    compress
    rotate 35
    daily
    maxage 60
    dateext
    notifempty
    missingok
    create 644 root root
    postrotate
     /etc/init.d/apache2 reload
    endscript

}

/var/log/apache2/error_log {
    compress
    rotate 35
    daily
    maxage 60
    dateext
    notifempty
    missingok
    create 644 root root
    postrotate
     /etc/init.d/apache2 reload
    endscript
    
}

Is there a better or more efficient way to rotate these logs on a daily basis at midnight? I tried adding this to one of my virtual host conf files - CustomLog “|/usr/sbin/rotatelogs /opt/www/awesome-project/log/access.%Y-%m-%d.log 86400” combined but the logs still didn’t rotate.

Thanks.

Wow! A month later and no help. For anyone else looking for a possible answer this is what I did. I moved the logrotate out of the /etc/cron.daily directory to /root and created a cron job - 0 0 * * * root /root/logrotate

On 2012-05-18 17:06, D8TA wrote:

> Wow! A month later and no help. For anyone else looking for a possible
> answer this is what I did. I moved the logrotate out of the
> /etc/cron.daily directory to /root and created a cron job - 0 0 * * *
> root /root/logrotate

I do not read all posts, and yours I did not notice at the time. I have
seen it now, as it has gone up in the queue, and what you did is precisely
what I would have suggested, if your machine is up continuously.

There is another method, which is adjusting “/etc/sysconfig/cron”.

[CRON]

Type: string

Default: “”

Type: time (eg: 14:00)

Default: nothing

At which time cron.daily should start. Default is 15 minutes after booting

the system. Due to the fact that cron script runs only every 15 minutes,

it will only run on xx:00, xx:15, xx:30, xx:45, not at the accurate time

you set.

DAILY_TIME=“23:55”
[CRON]


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)