LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 06-21-2011, 06:06 AM   #1
arumilli
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Rep: Reputation: Disabled
need to zip all the files excluding todays file


HI All,

At present in my server the log folder was filled up and causing memory issue.
So I am planning to write a script in such a way that the files which are older than 30 days will be deleted and also need to find the files which were not compressed and need to compress this file. Compression will exclude if the file was created on the same day.

I am new to Unix .Please bear me.
Edit/Delete Message
 
Old 06-21-2011, 06:57 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
What you need is logrotate. It can both delete older files and gzip the other ones except the log currently used. Take a look here for a little explanation about how to do that and feel free to ask if in doubt.
 
Old 06-21-2011, 07:18 AM   #3
arumilli
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks for you help.

I gone through the man pages.I tried to with some script.
Can you please have a look

Code:
"/var/log/jboss/*.log" {
missingok
copytruncate
rotate 30 -thinking that will keep 30days files
compress
notifempty
sharedscripts
postrotate
endscript
}
 
Old 06-21-2011, 09:02 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
If you don't run any command/script after the files have been rotated, you don't really need the postrotate/endscript and the sharedscripts directives. Also the rotate directive considers the number of rotations and yes... if the logs are rotated daily (as in your example, since you didn't specify any of weekly, monthly or size) they will be kept for 30 days. This should be fine:
Code:
/var/log/jboss/*.log {
missingok
copytruncate
rotate 30
compress
notifempty
}
You can create this file as /etc/logrotate.d/jboss and it should start to make its work as soon as the system crontab executes /etc/cron.daily/logrotate (be sure you have logrotate installed and the cron daemon is running).
 
Old 06-21-2011, 09:09 AM   #5
arumilli
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thank you very much..almost I found the script .

So the above script will work like it will delete old files which are older then 30 days and also zip the files which was less than 30 days...and it won't zip the file which was created on the same day .

Regards,
Sreenivas A.
 
Old 06-21-2011, 09:10 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You're welcome!
 
Old 06-21-2011, 09:14 AM   #7
arumilli
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Can you confirm it please?
 
Old 06-21-2011, 09:17 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Yes. I confirm.
 
Old 06-21-2011, 06:27 PM   #9
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 249Reputation: 249Reputation: 249
Quote:
Originally Posted by arumilli View Post
Can you confirm it please?
Just do as advised and you will know tomorrow !

Or is this homework ?
 
Old 06-27-2011, 01:38 AM   #10
arumilli
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
HI,

I tried but it's not working and where can check the logs of logrotate.

I ran externally logrotate -f /etc/logrotate.d/jboss but no luck.


Regards,
Sreenivas A.
 
Old 06-27-2011, 03:30 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Try to explicitly add
Code:
daily
in the logrotate's rule. However from the command line it should have worked with the -f option. Please, can you post the output of the following?
Code:
ls -l /var/log/jboss/
Thanks.
 
Old 06-27-2011, 03:56 AM   #12
arumilli
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks for your reply.Please find the list of files contained in /var/log/folder

Code:
total 4327304
-rw-rw-r-- 1 jboss jboss      64049 Jun 23 05:13 boot.log
-rw-rw-r-- 1 jboss jboss  508271933 Jun 27 08:54 server.log
-rw-rw-r-- 1 jboss jboss     364147 Jun 14 05:46 server.log.140611.gz
-rw-rw-r-- 1 jboss jboss    4216206 May 11 23:59 server.log.2011-05-11.gz
-rw-rw-r-- 1 jboss jboss    3689292 May 12 23:59 server.log.2011-05-12.gz
-rw-rw-r-- 1 jboss jboss    3146007 May 13 23:59 server.log.2011-05-13.gz
-rw-rw-r-- 1 jboss jboss    2651037 May 14 23:59 server.log.2011-05-14.gz
-rw-rw-r-- 1 jboss jboss    2587786 May 15 23:59 server.log.2011-05-15.gz
-rw-rw-r-- 1 jboss jboss    5408495 May 16 23:59 server.log.2011-05-16.gz
-rw-rw-r-- 1 jboss jboss    4623449 May 17 23:59 server.log.2011-05-17.gz
-rw-rw-r-- 1 jboss jboss    3108773 May 18 23:59 server.log.2011-05-18.gz
-rw-rw-r-- 1 jboss jboss    2839818 May 19 23:59 server.log.2011-05-19.gz
-rw-rw-r-- 1 jboss jboss    2300461 May 20 23:59 server.log.2011-05-20.gz
-rw-rw-r-- 1 jboss jboss    2095119 May 21 23:59 server.log.2011-05-21.gz
-rw-rw-r-- 1 jboss jboss    2295892 May 22 23:59 server.log.2011-05-22.gz
-rw-rw-r-- 1 jboss jboss    4861245 May 23 23:59 server.log.2011-05-23.gz
-rw-rw-r-- 1 jboss jboss    2610895 May 24 23:59 server.log.2011-05-24.gz
-rw-rw-r-- 1 jboss jboss    3145687 May 25 23:59 server.log.2011-05-25.gz
-rw-rw-r-- 1 jboss jboss    2277070 May 26 23:59 server.log.2011-05-26.gz
-rw-rw-r-- 1 jboss jboss    2370753 May 27 23:59 server.log.2011-05-27.gz
-rw-rw-r-- 1 jboss jboss    2109739 May 28 23:59 server.log.2011-05-28.gz
-rw-rw-r-- 1 jboss jboss    1977268 May 29 23:59 server.log.2011-05-29.gz
-rw-rw-r-- 1 jboss jboss    2453366 May 30 23:59 server.log.2011-05-30.gz
-rw-rw-r-- 1 jboss jboss    5974722 May 31 23:59 server.log.2011-05-31.gz
-rw-rw-r-- 1 jboss jboss    2884018 Jun  1 23:59 server.log.2011-06-01.gz
-rw-rw-r-- 1 jboss jboss   21393395 Jun  2 23:59 server.log.2011-06-02.gz
-rw-rw-r-- 1 jboss jboss   42313179 Jun  3 23:59 server.log.2011-06-03.gz
-rw-rw-r-- 1 jboss jboss   49228194 Jun  4 23:59 server.log.2011-06-04.gz
-rw-rw-r-- 1 jboss jboss   38353799 Jun  5 23:59 server.log.2011-06-05.gz
-rw-rw-r-- 1 jboss jboss   26244924 Jun  6 23:59 server.log.2011-06-06.gz
-rw-rw-r-- 1 jboss jboss   27580093 Jun  7 23:59 server.log.2011-06-07.gz
-rw-rw-r-- 1 jboss jboss   25492794 Jun  8 23:59 server.log.2011-06-08.gz
-rw-rw-r-- 1 jboss jboss   28588754 Jun  9 23:59 server.log.2011-06-09.gz
-rw-rw-r-- 1 jboss jboss   40368128 Jun 10 23:59 server.log.2011-06-10.gz
-rw-rw-r-- 1 jboss jboss   35676700 Jun 11 23:59 server.log.2011-06-11.gz
-rw-rw-r-- 1 jboss jboss   36157773 Jun 12 23:59 server.log.2011-06-12.gz
-rw-rw-r-- 1 jboss jboss   62474133 Jun 13 23:59 server.log.2011-06-13.gz
-rw-rw-r-- 1 jboss jboss   23496019 Jun 14 23:59 server.log.2011-06-14.gz
-rw-rw-r-- 1 jboss jboss   53333732 Jun 15 23:59 server.log.2011-06-15.gz
-rw-rw-r-- 1 jboss jboss   47484835 Jun 21 07:48 server.log.2011-06-16.tgz
-rw-rw-r-- 1 jboss jboss   57036999 Jun 21 07:50 server.log.2011-06-17.tgz
-rw-rw-r-- 1 jboss jboss    3758424 Jun 21 07:52 server.log.2011-06-18.tgz
-rw-rw-r-- 1 jboss jboss    4226795 Jun 21 07:52 server.log.2011-06-19.tgz
-rw-rw-r-- 1 jboss jboss   25805007 Jun 20 23:59 server.log.2011-06-20.gz
-rw-rw-r-- 1 jboss jboss  206848410 Jun 22 05:36 server.log.2011-06-21.tgz
-rw-rw-r-- 1 jboss jboss  123197850 Jun 23 05:51 server.log.2011-06-22.tgz
-rw-rw-r-- 1 jboss jboss   63750819 Jun 24 06:20 server.log.2011-06-23.tgz
-rw-rw-r-- 1 jboss jboss   56618288 Jun 25 18:27 server.log.2011-06-24.tgz
-rw-rw-r-- 1 jboss jboss   26982096 Jun 26 07:36 server.log.2011-06-25.tgz
-rw-rw-r-- 1 jboss jboss 2720943191 Jun 26 23:59 server.log.2011-06-26
-rw-rw-r-- 1 jboss jboss     845332 May 13 11:18 server.log.app1.gz
 
Old 06-29-2011, 05:15 AM   #13
arumilli
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Any inputs please...
 
  


Reply


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
Shell Script for Identifying the file and zip all files, move the files to Target Dir gvenkat Linux - Newbie 3 05-07-2011 11:53 AM
[SOLVED] Linux zip, excluding whole directory path SirLouen Linux - Software 1 09-12-2010 04:40 PM
Delete files in folder before todays date dave7802 Linux - Newbie 1 09-14-2009 06:03 AM
Uploading all files with todays date via kermit isourcemarketing Programming 2 08-26-2007 09:27 PM
Excluding directories from zip files jonathanztaub Linux - General 1 05-17-2004 03:17 AM


All times are GMT -5. The time now is 08:10 AM.

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