The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compress files >2GB xavix Linux 2 04-03-2009 01:06 PM
compress files lesstjm Shell Programming and Scripting 2 11-10-2008 06:26 AM
Compress files on NAS kamathg Filesystems, Disks and Memory 0 08-11-2008 11:04 AM
Compress files indira UNIX for Dummies Questions & Answers 3 05-30-2007 12:23 AM
How to Compress log files? redlotus72 UNIX for Dummies Questions & Answers 1 02-23-2005 06:07 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-09-2009
skmdu skmdu is online now
Registered User
  
 

Join Date: Jul 2009
Posts: 124
compress the log files

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 using logrotate, but I couldn't.

It is really thankful, if you give, even some other mechanism to compress and keep only last 5 days logs.
  #2 (permalink)  
Old 10-09-2009
dr.house dr.house is offline
Registered User
  
 

Join Date: Dec 2008
Location: Switzerland
Posts: 229
logrotate
  #3 (permalink)  
Old 10-09-2009
skmdu skmdu is online now
Registered User
  
 

Join Date: Jul 2009
Posts: 124

Code:
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

Its compressing all the log files and its not removing log files. Any input on this?
  #4 (permalink)  
Old 10-12-2009
skmdu skmdu is online now
Registered User
  
 

Join Date: Jul 2009
Posts: 124
Kindly review my last input on this..

Any help is really appreciated..
  #5 (permalink)  
Old 10-12-2009
dr.house dr.house is offline
Registered User
  
 

Join Date: Dec 2008
Location: Switzerland
Posts: 229
Quote:
Originally Posted by skmdu View Post
Code:
/var/log/appn/*.log {
 daily
 compress
 rotate 5
}
How about ...


Code:
/var/log/appn/*.log {
   daily
   rotate 5
   postrotate
      /etc/init.d/tomcat restart
   endscript
   compress
}

  #6 (permalink)  
Old 10-12-2009
pludi's Avatar
pludi pludi is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,927
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.

---------- Post updated at 14:20 ---------- Previous update was at 14:18 ----------

To keep logrotate from creating or truncating the original logs, set these options:
Code:
nocreate
nocopy
nocopytruncate

which are all described in the man page:
Code:
       nocopy Do  not copy the original log file and leave it in place.  (this
              overrides the copy option).


       nocopytruncate
              Do not truncate the original log file in place after creating  a
              copy (this overrides the copytruncate option).


       nocreate
              New  log  files  are  not  created  (this  overrides  the create
              option).

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0