Setpup Logrotate on linux systems

Will discuss the setting up of log rotation for tomcat in linux systems.

I am working on rhel. logrotate.d is the default rhel linux systems log rotation service.The script will

The home location for logrotate.d is under

cd /etc/logrotate.d

create new file called tomcat

vim tomcat

add the below entries in the file and save it .

opt/tomcat/logs/*.log {
daily
copytruncate
rotate 5
compress
delaycompress
missingok
shred
maxage 5
postrotate
find /opt/tomcat/logs -maxdepth 1 -mtime +4 -name “*.gz” -delete
find /opt/tomcat/logs -maxdepth 1 -mtime +4 -name “*.1” -delete
find /opt/tomcat/logs -size 0 -print0 |xargs -0 rm -f
endscript
}
/opt/tomcat/logs/*.txt {
daily
copytruncate
rotate 5
compress
delaycompress
missingok
shred
maxage 5
postrotate
find /opt/tomcat/logs -maxdepth 1 -mtime +4 -name “*.gz” -delete
find /opt/tomcat/logs -maxdepth 1 -mtime +4 -name “*.1” -delete
find /opt/tomcat/logs -size 0 -print0 |xargs -0 rm -f
endscript
}
/opt/tomcat/logs/*.out {
daily
copytruncate
rotate 5
compress
delaycompress
missingok
shred
maxage 5
postrotate
find /opt/tomcat/logs -maxdepth 1 -mtime +4 -name “*.gz” -delete
find /opt/tomcat/logs -maxdepth 1 -mtime +4 -name “*.1” -delete
find /opt/tomcat/logs -size 0 -print0 |xargs -0 rm -f
endscript
}

man/help page for the log rotate will be found in the below link http://www.linuxcommand.org/man_pages/logrotate8.html

add the script to rotate to the root user crontab.

crontab -e -u root

add the below line and save the file .

0 1 * * * /usr/sbin/logrotate /etc/logrotate.conf > /dev/null 2>&1
Like what you read? Give Venkata Chitturi a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.