Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-26-2011, 09:53 AM   #1
LQ Newbie
Registered: Dec 2005
Posts: 22

Rep: Reputation: 0
script to find and compress old logs that are not compresses

we have a system that generates large logs in hourly basis with the name format ex: addressprint_log.20111226000000. The system is supposed to compress logs older than 7 days but sometimes it miss logs filling up space.

I started to use gzip with find command but it goes through all logs from the beginning and passing ones already zipped.

Can someone please help with a script to find and compress logs older than 7 days which are not already compresses?

thanks in advance.
Old 12-26-2011, 10:01 AM   #2
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 191Reputation: 191
I think what you are looking for is logrotate.

"man logrotate" for more info.
Old 12-26-2011, 11:40 AM   #3
Senior Member
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107

You can simply schedule below line in crontab

find /your/dir -mtime +7 | xargs gzip


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to compress pnmanojshenoy Linux - Newbie 2 06-07-2010 02:26 PM
script to compress a directory and then delete older than 7 days replica88 Linux - General 3 02-03-2010 08:21 PM
How to make/configure script to extract, ecit and compress initrd.gz ?? linus72 Linux - General 14 10-22-2009 07:31 PM
Logrotate: compress logs in a temp directory gbratig AIX 3 04-12-2008 11:42 PM
script needed to compress files kingkhankk Linux - General 2 03-04-2008 12:20 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:48 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration