[asterisk-users] Record() : How to get filename created with %d?

Tony Mountifield tony at softins.clara.co.uk
Tue Nov 13 03:32:54 CST 2007

In article <g5rhj39jpn583h0t6q94s19vesjssbn792 at 4ax.com>,
Vincent <vincent.delporte at bigfoot.com> wrote:
> On Mon, 12 Nov 2007 09:58:50 +0000 (UTC), tony at softins.clara.co.uk
> (Tony Mountifield) wrote:
> >I'm a little surprised at the variety of band-aid suggestions that have
> >been posted. All you need to do is refer to "show application record",
> >and you uwill see that the generated filename is available by using
> Thanks for the tip. The reason I was looking for another solution is
> that I couldn't get the value of the variable... but it's working now.
> I'm not comfortable yet with functions/applications, and have no idea
> what I did wrong :-/
> BTW, what's the difference between functions and applications?

An application is a "command" executed by a dialplan priority, such as
Record, Verbose, TrySystem, etc. in your example below.

A function needs to be evaluated inside ${ } and returns a string value
that is substitued in place of the ${ }, such as STRFTIME in your
second example.

> For those interested, here's some working code:
> ======
> exten => 555,1,Record(/tmp/msg%d.wav,3,30)
> exten => 555,n,Verbose(${RECORDED_FILE})
> exten => 555,n,TrySystem(mv ${RECORDED_FILE}.wav /var/www/asterisk/)

The above line might be dangerous. The way %d works is that Record
tries %d=1, then 2 and so on, until it finds a value that doesn't
already exist.

If you have, say, foo%d as the filename, it creates foo1.wav, but then
when you move foo1.wav to a different directory, Record will use foo1.wav
again the next time.

You can avoid that by using ln instead of mv, but when you want to
delete the file, you must remember to do so in both places.

Or you could symlink one directory to another.

> exten => 555,n,ExecIf($[${SYSTEMSTATUS} != SUCCESS],Verbose,Failed
> moving WAV file)
> ======
> Another way to generate a filename dynamically, using the current date
> + time:
> ======
> exten =>
> _[1-4],n,Set(CALLTIME=${STRFTIME(${EPOCH},GMT+1,%d-%b-%Y-%Hh%M)})
> exten => _[1-4],n,Record(/tmp/${CALLTIME}.wav,3,30)
> exten => _[1-4],n,TrySystem(mv /tmp/${CALLTIME}.wav
> /var/www/asterisk/)
> exten => _[1-4],n,ExecIf($[ ${SYSTEMSTATUS} != SUCCESS
> ],Verbose,Failed moving WAV file)
> ======

That certainly would avoid the problem of reusing the same %d, but would
break if you had two calls in the same second.

Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org

More information about the asterisk-users mailing list