Configure logrotate for Asterisk logfiles on CentOS

Asterisk PBXlogrotate is an utility specially designed for ease rotation of large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.

Normally, logrotate is run as a daily cron job. By default it lacks the configuration file for Asterisk logfiles. Here I’ll suggest an example but you may customize it based on your needs.

Open /etc/logrotate.d/asterisk file with your favorite text editor:

and paste the following:

Now you can check if it’s working:

Now check /var/log/asterisk and ensure logfiles have been rotated.

In case you run FreePBX the owner of /var/log/asterisk directory is usually asterisk.asterisk . In this case you will get logrotate error:

error: skipping “/var/log/asterisk/full” because parent directory has insecure permissions (It’s world writable or writable by group which is not “root”) Set “su” directive in config file to tell logrotate which user/group should be used for rotation.

In this case add su directive as follows:

Run:

to get details about configuration file directives.

Want me to do this for you? Drop me a line: itgalaxyzzz {at} gmail [dot] com