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 WebCDR.com, 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.

Setup

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

  • asterisk-cdr-rollover.sh – 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/asterisk-cdr-rollover.sh 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: https://github.com/earlruby/asterisk-cdr-rollover. The code is licensed under the GNU General Public License (GPL-2.0).

I hope you find this useful.

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

  1. 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 Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.