Solved

How to delete log files which older than 3 days through script?

Posted on 2007-04-03
7
458 Views
Last Modified: 2013-11-21
I am using AIX unix server. In thati need to delete all log files other than files which is created in last three days. How to set logrotate on AIX ? How to do this is script ? It have to run everyday ,compare date time & delete old file ( only 3 days from current have to remain)
0
Comment
Question by:rammaghenthar
  • 3
  • 3
7 Comments
 
LVL 33

Expert Comment

by:NJComputerNetworks
ID: 18850328
What version of Microsoft Systems Management Server are you using (2.0, 2003, R2)?
0
 
LVL 6

Expert Comment

by:DocGyver
ID: 18867858
Do you want to do this with logrotate or with a shell script?  You mention both.  For a shell script you can do something like this:

find /var/log/logdir -daystart -mtime +3 -exec rm {} \;

That will remove all files older than 3 days even in subdirectories of the specified directory.  If the folder you are cleaning up has subdirectories that you want to leave alone then let me know and I can give you a find command to skip subdirectories.

If you only want to get files that match a particular pattern then add: -name yourwildcard.*
thus:

find /var/logl/logdir -daystart -mtime +3 -name "yourwildcard.*" -exec rm {} \;

Doc..
0
 
LVL 2

Author Comment

by:rammaghenthar
ID: 18873112
is it possible to find and nullify the files, for some log files this setup is need ?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 6

Expert Comment

by:DocGyver
ID: 18874205
What do you mean by "nullify"?

The "find" command has some very sophisticated options for selecting files so if you are looking to restrict that set by something other than time I'm pretty sure it is possible.

You might want to check out the man pages.
0
 
LVL 2

Author Comment

by:rammaghenthar
ID: 18882148
Hi  I have tried
updates below
 find /tmp -daystart -mtime +3 -exec rm {} \;
find: 0652-017 -daystart is not a valid option.
0
 
LVL 2

Author Comment

by:rammaghenthar
ID: 18882164
I had tried to delete 3 days older files & it is said below
0
 
LVL 6

Accepted Solution

by:
DocGyver earned 50 total points
ID: 18882220
oops.  "-daystart" is a linux find command option.  You can drop it off but then it calculates from the current time.  So for instance if you run it at 3:00 in the afternoon you would get files that are 3 days old as of that time.  So the new command would be:

find /tmp -mtime +3 exec rm {} \;
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On a regular basis I get questions about slow RDP performance, RDP connection problems, strange errors and even BSOD, remote computers freezing or restarting after initiation of a remote session. In a lot of this cases the quick solutions made b…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question