Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-04-03
7
Medium Priority
?
467 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 150 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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…
Suggested Courses

618 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