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

Earl Ruby earl at switchmanagement.com
Mon Dec 3 23:59:22 CST 2012


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.

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/sbin. 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.




More information about the asterisk-users mailing list