Bulk renaming audio files

Some PBXs - especially the ones based on FreePBX 2.11 - may save a prepending '+' sign in audio file names. Those file names will look like:

q-123-+12225555688-20140520-071636-140058812.32217.wav

Where '+12225555688' is the number dialed. These names are not compatible with some versions of QueueMetrics.

Removing the initial character in new files

Add the following to '/etc/asterisk/extension_custom.conf':

[from-pstn-custom]
exten => _X!,1,GotoIf($["${CALLERID(num):0:1}" = "+"]?plusstart:noplusstart)
exten => _X.,n(plusstart),NoOp(Changing Caller ID number from ${CALLERID(num)} to ${CALLERID(num):1})
exten => _X.,n,Set(CALLERID(num)=${CALLERID(num):1})
exten => _X.,n,Set(CALLERID(ANI)=${CALLERID(num)})
exten => _X!,n(noplusstart),NoOp(Caller ID does not need adjustment)

Then load the new dialplan code with:

asterisk -rx 'dialplan reload'

This will fix all calls going forward.

Renaming old files to remove the plus character

To fix all calls retroactively, you need to rename the existing call recordings like in:

for d in `find /var/spool/asterisk/monitor -mindepth 3 -type d`;do
    cd $d;
    for i in *.wav; do
        mv $i ${i/+/}
    done
done
This recipe was originally contribuited by one user on our forums who wished to remain anonymous.