Hi,
I have an application which creates the logs in a date wise.
like,
Code:
tomcat_access_log.2009-09-12.log
tomcat_access_log.2009-09-11.log
tomcat_access_log.2009-09-10.log
tomcat_access_log.2009-09-09.log
tomcat_access_log.2009-09-08.log
tomcat_access_log.2009-09-07.log
Now my requirement is to compress all the log files and keep only last 5 days compressed logfiles always.
For ex:
Code:
If today is 10/09/2009 ( mm/dd/yyyy)
then my log directory ( /var/log/appn) should looks like,
tomcat_access_log.2009-10-09.log
tomcat_access_log.2009-10-08.log.gz
tomcat_access_log.2009-10-07.log.gz
tomcat_access_log.2009-10-06.log.gz
tomcat_access_log.2009-10-05.log.gz
tomcat_access_log.2009-10-04.log.gz
I tried to get it done through the logrotate,
Before logrotate
-rw-r--r-- 1 root root 0 Oct 9 02:46 tomcat_access_log.2009-10-01.log
-rw-r--r-- 1 root root 0 Oct 9 02:46 tomcat_access_log.2009-09-30.log
-rw-r--r-- 1 root root 0 Oct 9 02:46 tomcat_access_log.2009-09-29.log
-rw-r--r-- 1 root root 0 Oct 9 02:46 tomcat_access_log.2009-09-28.log
-rw-r--r-- 1 root root 0 Oct 9 02:46 tomcat_access_log.2009-09-27.log
-rw-r--r-- 1 root root 0 Oct 9 02:46 tomcat_access_log.2009-09-26.log
-rw-r--r-- 1 root root 0 Oct 9 02:46 tomcat_access_log.2009-09-25.log
-rw-r--r-- 1 root root 0 Oct 9 02:46 tomcat_access_log.2009-09-24.log
-rw-r--r-- 1 root root 0 Oct 9 02:46 tomcat_access_log.2009-09-23.log
content of /etc/logrotate.conf
/var/log/appn/*.log {
daily
compress
rotate 5
}
After logrotate
-rw-r--r-- 1 root root 20 Oct 9 02:54 tomcat_access_log.2009-10-01.log.1.gz
-rw-r--r-- 1 root root 0 Oct 9 02:54 tomcat_access_log.2009-10-01.log
-rw-r--r-- 1 root root 20 Oct 9 02:54 tomcat_access_log.2009-09-30.log.1.gz
-rw-r--r-- 1 root root 0 Oct 9 02:54 tomcat_access_log.2009-09-30.log
-rw-r--r-- 1 root root 20 Oct 9 02:54 tomcat_access_log.2009-09-29.log.1.gz
-rw-r--r-- 1 root root 0 Oct 9 02:54 tomcat_access_log.2009-09-29.log
-rw-r--r-- 1 root root 20 Oct 9 02:54 tomcat_access_log.2009-09-28.log.1.gz
-rw-r--r-- 1 root root 0 Oct 9 02:54 tomcat_access_log.2009-09-28.log
-rw-r--r-- 1 root root 20 Oct 9 02:54 tomcat_access_log.2009-09-27.log.1.gz
-rw-r--r-- 1 root root 0 Oct 9 02:54 tomcat_access_log.2009-09-27.log
-rw-r--r-- 1 root root 20 Oct 9 02:54 tomcat_access_log.2009-09-26.log.1.gz
-rw-r--r-- 1 root root 0 Oct 9 02:54 tomcat_access_log.2009-09-26.log
-rw-r--r-- 1 root root 20 Oct 9 02:54 tomcat_access_log.2009-09-25.log.1.gz
-rw-r--r-- 1 root root 0 Oct 9 02:54 tomcat_access_log.2009-09-25.log
-rw-r--r-- 1 root root 20 Oct 9 02:54 tomcat_access_log.2009-09-24.log.1.gz
-rw-r--r-- 1 root root 0 Oct 9 02:54 tomcat_access_log.2009-09-24.log
-rw-r--r-- 1 root root 20 Oct 9 02:54 tomcat_access_log.2009-09-23.log.1.gz
-rw-r--r-- 1 root root 0 Oct 9 02:54 tomcat_access_log.2009-09-23.log
How to achieve my need mentioned above? Any help is really appreciated.