How to roll-over / move / rotate an Asterisk Master.csv call detail record (CDR) file every 15 minutes

If you are trying to provide CDR files to a billing service, such as, you need to provide files containing your latest call data every 15 minutes or so. I wrote a script and a cron job that will create a new CDR file every 15 minutes with the latest CDR records, without interrupting call flow. You do not need to make any changes to your Asterisk configuration to use these scripts.


There are two files that you need to install on your Asterisk server:

  • – A bash shell script. Copy this file into /usr/local/bin. This script moves the file /var/log/asterisk/cdr-csv/Master.csv to a new file named /var/log/asterisk/cdr-csv/cdr-YYYYMMDDHHMISS.csv, where YYYYMMDDHHMISS is the current time. A new zero-byte Master.csv file is created using the default umask of the user running the asterisk process. Asterisk will start writing to the new Master.csv file at the end of the next call.
  • asterisk-cdr-rollover – This is a cron job. Copy it into /etc/cron.d and it will run the /usr/local/sbin/ script once every 15 minutes.

The cron job is set up to run as the user “asterisk”. If you are running asterisk as “root” or some other user name, edit the asterisk-cdr-rollover cron job and change the name of the user running the script to the same name as the user running the asterisk process.

The latest versions of these two files can be downloaded from GitHub: The code is licensed under the GNU General Public License (GPL-2.0).

I hope you find this useful.

1 Comment »

  1. Winston Said,

    January 29, 2014 @ 2:29 pm

    Thank you for this, we were able to use it smoothly,

    I’ve left the GNU code inside with your name on it.

    Thanks again

Leave a Comment