In Elastix users can listen to wav file recordings via the “Call Recordings” tab, This uses a field in the mysql cdr table to say where that recording is and what its called, In Elastix 2.5 they are now stored in year/month/day directory structure under /var/spool/asterisk/monitor so if the end user wants the recordings in mp3 format as many do its not just a case of converting them its also a case of updating the database.
Luckily this is fairly straight forward, its just a case of doing a quick query and then converting the file and the updating the database. First you have to install lame, This can be done simply with yum then write a script.
The script I use is simple with a bit of basic logging.
#!/bin/bash
user=USER
password=SECRET
mysql -u$user -p$password -s -N -D asteriskcdrdb<<<"select recordingfile from cdr where recordingfile LIKE '%.wav' AND calldate >= DATE_SUB(NOW(), INTERVAL 70 MINUTE)" > tmp_query
date >> /var/log/asterisk/mp3.log
while read pcmwav
do
mp3="$(echo $pcmwav | sed s/".wav"/".mp3"/)"
nice lame -b 16 -m m -q 9-resample "$pcmwav" "$mp3"
touch -r "$pcmwav" "$mp3" >> /var/log/asterisk/mp3.log
mysql -u$user -p$password -s -N -D asteriskcdrdb<<<"UPDATE cdr SET recordingfile='$mp3' WHERE recordingfile = '$pcmwav'"
echo $pcmwav >> /var/log/asterisk/mp3.log
echo "--------||-------" >> /var/log/asterisk/mp3.log
done < tmp_query
date >> /var/log/asterisk/mp3.log
echo "Done" >> /var/log/asterisk/mp3.log
echo "--------||-------" >> /var/log/asterisk/mp3.log
exit 1
As can be seen it steps through entry by entry converting and updating the DB, This example is cron’d to run hourly but does not delete the original wav file, this would be done in a separate script run weekly to remove old files. The reason to keep them is so that a backup of the original is held for a period in case of errors.
Hope this is of help to you and your users