logrotate: delete tomcat/jboss logs older than n days
If you don't want to use find
inside postrotate
, no, you can't.
logrotate
treats every instance of server.log
rotated by Tomcat/JBoss as a different file, and since they are unique, logrotate
will rotate them only once. maxage
- the directive that removes rotated logs older than n
days - is only checked if the logfile is to be rotated, so that maxage
is only executed once and can't keep track of the file's age.
However, if you change your mind about using find
, logrotate
can help you simplify the management of log files created by Tomcat and JBoss. I use it to compress and remove old files with a configuration file like this:
/path/to/logs/server.log.????-??-?? {
compress
compresscmd /usr/bin/bzip2
nocreate
nodateext
ifempty
missingok
rotate 1
size 0
start 0
lastaction
# Remove rotated files older than 180 days
find /path/to/logs -name 'server.log.????-??-??.0.bz2' -mtime +180 -exec rm {} \;
endscript
}
where:
rotate 1
andcompress
rename and compress, say,server.log.20131201
toserver.log.20131201.0.bz2
. The0
between the timestamp and the.bz2
extension comes fromstart 0
.size 0
makes sure that files are always renamed and compressed.- The
lastaction
block removes rotated files older than 180 days.
Wipe clean logfile on daily basis with logrotate
rotate 0
is redundant here, 0
is the default for rotation, which means, no rotation and old ones are removed.
You can test it using,
$ logrotate -f /etc/logrotate.d/docker
It might be better to test it by putting rotate 1
and then with rotate 0
to check if logrotate
is functioning correctly.
If logrotate
is installed correctly, then one would have a crontab
entry in /etc/cron.daily/logrotate
. This file reads the configuration file /etc/logrotate.conf
which includes anything under /etc/logrotate.d
HTH
Related Topics
Writing to Serial Port from Linux Command Line
Differencebetween Xterm-Color & Xterm-256Color
What Does Anon-Rss and Total-Vm Mean
Permanently Change Disassembly Flavor in Gdb
Getting Stty: Standard Input: Inappropriate Ioctl for Device When Using Scp Through an Ssh Tunnel
What's the Difference of Redirect an Output Using ">", "&>", ">&" and "2&>"
How to Concatenate Two Strings to Build a Complete Path
File Execution with Dot Space Versus Dot Slash
Error While Loading Shared Libraries: Libncurses.So.5:
What's the Difference Between Event-Driven and Asynchronous? Between Epoll and Aio
Bash: Let Statement VS Assignment
Append Text to File from Command Line Without Using Io Redirection
What Is the Recommended Way to Perform Source-Level Debugging of System Library Calls
Show Special Characters in Unix While Using 'Less' Command
How to Use an Older Version of Gcc in Linux
How to Make Grep Print the Lines Below and Above Each Matching Line