Solved

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

Posted on 2007-04-03
7
456 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Roaming profile & Office 365 3 96
Windows 10 Firewall question 5 83
Can I exclude specific directory with icacle command? 3 44
Server Backup on 2016 Essentials Box 1 58
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…
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.
The viewer will learn how to dynamically set the form action using jQuery.
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…

831 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