Solved

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

Posted on 2007-04-03
7
452 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.

Join & Write a Comment

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Remote Apps is a feature in server 2008 which allows users to run applications off Remote Desktop Servers without having to log into them to run the applications.  The user can either have a desktop shortcut installed or go through the web portal to…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now