Skip to end of metadata
Go to start of metadata

There are two other constructs we can use within our configuration files. They are #include and #exec.

The #include construct tells Asterisk to read in the contents of another configuration file, and act as though the contents were at this location in this configuration file. The syntax is #include filename, where filename is the name of the file you'd like to include. This construct is most often used to break a large configuration file into smaller pieces, so that it's more manageable.

The #exec takes this one step further. It allows you to execute an external program, and place the output of that program into the current configuration file. The syntax is #exec program, where program is the name of the program you'd like to execute.

Icon

Enabling #exec Functionality

The #exec construct is not enabled by default, as it has some risks both in terms of performance and security. To enable this functionality, go to the asterisk.conf configuration file (by default located in /etc/asterisk) and set execincludes=yes in the [options] section. By default both the [options] section heading and the execincludes=yes option have been commented out, you you'll need to remove the semicolon from the beginning of both lines.

Let's look at example of both constructs in action.

  • No labels

4 Comments

  1. Hi, I have a request please. someone could put an example of a shell script for the extensions.conf using #exec. I have a simple script, which use echo add an exten, but it doesn´t work...please help

    1. Something like:

      #exec /usr/bin/curl -s http://example.com/mystuff > /etc/asterisk/mystuff
      #include mystuff
      
  2. exec and include constructs don't work on the following config files:

    • asterisk.conf
    • modules.conf
    1. Please post this issue to https://issues.asterisk.org/jira to document these exceptions to the wiki, code, and other documentation.