I have to configure the logrotate.conf file on some Linux RedHat servers.
So, by default I seen the file is as follow:
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
minsize 1M
create 0664 root utmp
rotate 1
}
# system-specific logs may be also be configured here.
At this point I have a couple of questions for you:
1) As configurated, this file manages logs system files, correct?
2) Now, I have to manage log files (called monitoring.log) produced by a custom script created by myself (monitoring.sh).
I'd want this log be emptied everyday, at a certain hour, and old log files be archived everyday.
No, only wtmp will be rotated by default. Take a look in /etc/logrotate.d what else might get rotated.
What does the very first line in your logrotate.conf say? Did you read it? Did you understand it? If not, post concrete questions, but don't ask us to do your work.
This times I hope not to make a wrong question, but I didn't really understand how to synchronize my monitoring.sh custom script (see post below) and the actions of logrotate on monitoring.log.
Maybe logrotate starts at the end of monitoring.sh, or not?
First, drop the endscript directive. It's only valid if you've got a prerotate or postrotate somewhere in there.
Second, it depends on how logging is implemented in your script to say how to best inform it of a rotation. If you're just logging with lines like
echo "Log message" >> $log
or similar, you don't have to do anything. If your script only runs at intervals and probably won't cross times with logrotate, you don't have to do anything.
If, however, your script runs most of the time, and opens a file descriptor for the log at the beginning, you'll probably have to close and re-open that fd. The easiest way would be a trap on SIGHUP, and an appropriate postrotate script.