How to add a custom file in log rotation in linux ?

Today in this post, we will look how to add a custom file in log rotation.

This will help to do automated housekeeping on the server.

Lets suppose we have below two files causing issue after some days on the server and we want to rotate them.



I. Create log rotation configuration file.

[root@ngelinux001 ~]# cd /etc/logrotate.d/
[root@ngelinux001 logrotate.d]# touch licenselog
[root@ngelinux001 logrotate.d]#


II. Lets put the configuration like below.

[root@ngelinux001 logrotate.d]# cat licenselog
maxsize 500M
rotate 4
        /etc/init.d/Antivirus_agent stop; /bin/sleep 30; /etc/init.d/Antivirus_agent start
[root@ngelinux001 logrotate.d]#


III. Description

a. daily --> Runs the instructions daily
b. maxsize --> When file reaches 500MB or more, rotate it.
c. rotate 4 --> keep 4 backup log files at the location
d. sharedscripts and enscript --> Mentions the start and stop of the post script command.
e. postrotate --> Restarts the service post file rotation.


IV. Run the logrotate Script manually to test

# /usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf

Now check the path, and see the files must be rotated and service was restarted.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments