How to make custom logrotate script

Post Reply
User avatar
isscbta
Posts: 39
Joined: Mon Jul 19, 2021 1:41 am

Let's suppose that you want to crete new logrotate script in order to gzip some custom log files (we will take them as examples here).
Additionally, let's say we want to save the log archives only for the last 10 days.

In your SSH, as root, run:

Code: Select all

mcedit /etc/logrotate.d/custom
Here you will create file like this (instead of someuser insert desired user):

Code: Select all

/home/someuser/web/domain.com/public_html/var/log/*.log {
    daily
    size 1M
    missingok
    rotate 10
    compress
    delaycompress
    notifempty
    create 0644 someuser someuser
    su someuser someuser
}
And then run the test:

Code: Select all

logrotate -d -f /etc/logrotate.d/custom
And finally real initial run:

Code: Select all

logrotate -f /etc/logrotate.d/custom
Post Reply