[Asterisk-Dev] voicemail filenames

Aaron S. Joyner asjoyner at intrex.net
Wed Sep 29 07:00:00 MST 2004


Ben Merrills wrote:

><...>
>But if I delete any of the voicemails, then I have to renumber ALL of them.
><...>
>Could the voicemails be time stamped instead (unix file time style?) of
>msgXXXX format? This would mean you could delete a file, and not need to
>reorder files!
>  
>
First, let me say that I *do* think Asterisk should handle this aspect 
of the voicemail file handling better, and I haven't taken a look at the 
source, but I suspect it's written the way it is for performance 
reasons.  It's faster and safer from a memory-use perspective to just 
iterate through the list of known filenames until you do an fopen() on 
the first one that doesn't exist and stop there, as opposed to pulling 
in the entire list of files in the directory (which arguably might be 
300+ messages, as you demonstrate) and choosing which files are actually 
voicemail messages.  It could certainly be optimized in more 
external-modification-friendly ways, but as apparently neither you nor I 
have an immediate interest in tackling that problem, perhaps we should 
consider a different solution.  :)

It's not terribly difficult to renumber those files from the shell to 
deal with the problem efficiently, in the same manner Asterisk does.  
Consider this shell snippet, which rips through the appropriately 
numbered msg0000.* files and renumbers them in their existing sequence, 
in an asterisk-friendly sequential order:

#!/bin/bash
EXT=".wav"
cd test
COUNT=0000
ls -1 *$EXT | while read LINE; do
    if [ msg$COUNT$EXT != $LINE ]; then
        while [ -f msg$COUNT$EXT ]; do COUNT=`printf "%04d" \`expr 
$COUNT + 1\``; done;
        mv -v "$LINE" msg$COUNT$EXT;
    fi
    COUNT=`printf "%04d" \`expr $COUNT + 1\``
done


Hope it's helpful to someone.  :)  Do note that it will move anything 
with the appropriate $EXT (set at the top of the script) - so if for 
some silly reason you have other files in that directory with the same 
extension, you better move them out of harms way or have them made into 
voicemails.

-- 
Aaron S. Joyner
System Administrator
Intrex.net Internet Services
(919) 573-5488




More information about the asterisk-dev mailing list