[CentOS] Silly logrotate question

Thu Oct 20 01:26:24 UTC 2011
Edo <ml2edwin at gmail.com>

Hi,

I’m probably missing something here...


On Wednesday, October 19, 2011 at 6:14 PM, John Kennedy wrote:

> Ok, I have Googled this and either I am not asking the right way or I just
> can't see what's in front of me (sorry)...
>  
> We have log files called app.2011-10-119.log (with the date changing every
> day). The log is created by the application each day at midnight.
> I have logrotate set to rotate files ending in .log at 4am, with
> copytruncate on by default.
> If I list the files I see all the old app.2011-10-<X>.log files with a 0
> file size.
> If I turn off copytruncate, the current days log file will be removed
> everyday at 4am.

You mean current day’s? And by “current day’s”, you mean the logs after midnight up to 4 a.m.?
  
> How can I satisfy both the need to remove yesterday's log file while keeping
> the current day?

Why not run your logrotate just right after midnight? (Instead of at 4 a.m.)
  
> Here is the logrotate file:
>  
> /var/log/app/*.log {
>  daily
>  rotate 10
>  compress
>  missingok
>  notifempty
>  create 0644 user user
> }
>  
> I added notifempty to keep the old empty log files from being compressed...

Or, forget about logrotate and simply run a script right after midnight with something like the ff:

  rm app.`date --date="yesterday" +%Y-%m-%d`.log

> Thanks,
> John
>  
>  John Kennedy
>  
  
HTH,

--  
- Edo - mailto:ml2edwin at gmail.com
“Do not hold back good from those to whom it is owing, when it
 happens to be in the power of your hand to do [it].”—Proverbs 3:27