Solved

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

Posted on 2007-04-03
7
455 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
The problems with reply email signatures

Do you wish that you could place an email signature under a reply? Well, unfortunately, you can't. That great Exchange/Office 365 signature you've created will just appear at the bottom of an email chain. What a pain! Is there really no way to solve this? Well, there might be...

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
OWA and AppPool problem 20 126
Register AutoHotkey 12 55
Active DirectoryScript to change the Pager Field 1 49
Need script to search multiple files in one drive 13 35
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
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 …

895 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

18 Experts available now in Live!

Get 1:1 Help Now