In this article, we will see how to change the log rotation script of a log file and test it in Linux.
Lets have a look at the steps.
1. Make required changed in the logrotate service config file.
[root@ngelinux001 logrotate.d]# pwd
/etc/logrotate.d/
[root@ngelinux001 logrotate.d]# cat httpd
/var/log/httpd/*log {
missingok
notifempty
sharedscripts
compress
postrotate
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
}
[root@ngelinux001 logrotate.d]#
2. Now test the changes if working fine.
[root@ngelinux001 logrotate.d]# logrotate -d ./httpd
reading config file ./httpd
reading config info for /var/log/httpd/*log
Handling 1 logs
rotating pattern: /var/log/httpd/*log 1048576 bytes (no old logs will be kept)
empty log files are not rotated, old logs are removed
considering log /var/log/httpd/access_log
log does not need rotating
considering log /var/log/httpd/accessreports_80-access_log
log does not need rotating
considering log /var/log/httpd/accessreports_80_error_log
log does not need rotating
considering log /var/log/httpd/error_log
log does not need rotating
considering log /var/log/httpd/ssl_access_log
log does not need rotating
considering log /var/log/httpd/ssl_error_log
log needs rotating
considering log /var/log/httpd/ssl_request_log
log does not need rotating
rotating log /var/log/httpd/ssl_error_log, log->rotateCount is 0
dateext suffix '-20220629'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/httpd/ssl_error_log.1.gz to /var/log/httpd/ssl_error_log.2.gz (rotatecount 1, logstart 1, i 1),
renaming /var/log/httpd/ssl_error_log.0.gz to /var/log/httpd/ssl_error_log.1.gz (rotatecount 1, logstart 1, i 0),
renaming /var/log/httpd/ssl_error_log to /var/log/httpd/ssl_error_log.1
disposeName will be /var/log/httpd/ssl_error_log.1.gz
running postrotate script
running script with arg /var/log/httpd/*log : "
/sbin/service httpd reload > /dev/null 2>/dev/null || true
"
compressing log with: /bin/gzip
removing old log /var/log/httpd/ssl_error_log.1.gz
error: error opening /var/log/httpd/ssl_error_log.1.gz: No such file or directory
[root@ngelinux001 logrotate.d]#
We can see the debug messages in the logs above and analyze how it rotates the file after making the changes.
