Asterisk, and other worldly endeavours.

A blog by Leif Madsen

Converting multiple exten => lines to using same => in Asterisk dialplan


Last week I wanted to start changing some 1.4 based Asterisk dialplan to a 1.8 based Asterisk system, and in that process wanted to convert lines like:

exten => _NXXNXXXXXX,1,NoOp()
exten => _NXXNXXXXXX,2,GotoIf($[...]?reject,1)
exten => _NXXNXXXXXX,3,Dial(SIP/foo/${EXTEN})
...

into using the same => prefix:

exten => _NXXNXXXXXX,1,NoOp()
 same => n,GotoIf($[...]?reject,1)
 same => n,Dial(SIP/foo/${EXTEN})

In order to do that, Mike King helped me out with the following regular expressing which I used in vim:

%s/exten\s*=>\s*[^,]\+,\s*[n2-9]/ same => n/g
Advertisements

Written by Leif Madsen

2012/01/16 at 8:28 am

5 Responses

Subscribe to comments with RSS.

  1. How about the equivalent to convert 1.6 dial plans with “n” priorities too?

    Cassius Smith

    2012/01/16 at 2:27 pm

    • No changes necessary, works both with numbered priorities and ‘n’ priorities. That’s what the [n2-9] part means.

      Leif Madsen

      2012/01/16 at 3:24 pm

  2. What is the point to convert?
    The old one configuration from 1.4 will not work in 1.8?

    Mindaugas

    2012/01/24 at 3:27 am

    • Asterisk will work with the old method, but the new method is much easier to manage. Imagine you have a 47 line extension where every single line starts with something like:

      exten => _[0-9*#]XX.,———

      Now imagine you make a mistake, or want to change that pattern match. Either finding the mistake in 47 lines of dialplan is hard, or changing the pattern match is hard. If you use the ‘same =>’ methodology then you only change it on the first line, not all subsequent lines.

      Leif Madsen

      2012/01/24 at 7:47 am

      • Thank you for explanation! Will migrate 1000+ servers from 1.4 to 1.8 after few months. Trying to be ready…

        Mindaugas

        2012/01/24 at 7:54 am


Comments are closed.

%d bloggers like this: