1748274 Members
4120 Online
108760 Solutions
New Discussion

log rotation

 
tempsample
Frequent Advisor

log rotation

Hi ,

 

I want to perform some log rotation.

 

Just for simple,I have put all those in find command in a file and I will execute the file using cron.

 

find /tmp -type f -name "*.log" -mtime +3 -exec /usr/bin/gzip {} \;

 

zipped file will be removed after 10 days


find /tmp -type f -name "*.log.gz" -mtime +100 -exec rm -rf {} \;

 

is my understanding correct or any other method to perform log rotation.

 

 

1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: log rotation

>find /tmp -type f -name "*.log" -mtime +3 -exec /usr/bin/gzip {} \;

 

(You really shouldn't have logs in /tmp, if that's not just an example.)

 

You can speed this up by using: -exec /usr/bin/gzip {} +

 

>zipped file will be removed after 10 days

 

You have 100 below.

>find /tmp -type f -name "*.log.gz" -mtime +100 -exec rm -rf {} \;

 

Since you have "-type f", you should just use: -exec rm -f {} +

 

>is my understanding correct or any other method to perform log rotation.

 

Seems fine.  Have you looked into logrotate?