• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to use Variables and Global Variables using Asterisk Dialplan Context on Rocky Linux 9.4

  • 00:40 Cat /etc/os-release
  • 00:56 systemctl status asterisk
  • 01:24 cd /etc/asterisk/
  • 01:38 vim pjsip.conf
  • 02:16 vim extensions.conf
  • 03:38 asterisk -rvvvvvvvvvvvvvvv
  • 03:47 dialplan reload
  • 04:12 exit
  • 04:15 vim extensions.conf
  • 04:58 asterisk -rvvvvvvvvvvv
  • 05:06 dialplan reload
{{postValue.id}}

To Use Variables And Global Variables Using Asterisk Dialplan Context On Rocky Linux 9.4

Introduction:

Asterisk offers the ability to create customized call flow patterns to effectively manage unexpected changes and improve the efficiency of your communication system. It allows for the utilization of global, shared, and channel-specific variables for command arguments. Additionally, Asterisk includes predefined variables to enhance functionality.

Procedure:

Step 1: Check the OS version by using the below command.

[root@Linuxhelp ~]# cat /etc/os-release
NAME="Rocky Linux"
VERSION="9.4 (Blue Onyx)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.4"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Rocky Linux 9.4 (Blue Onyx)"
ANSI_COLOR="0;32"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
SUPPORT_END="2032-05-31"
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
ROCKY_SUPPORT_PRODUCT_VERSION="9.4"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.4"

Step 2: Check the status of the Asterisk services by using the below command.

[root@Linuxhelp ~]# systemctl status asterisk
● asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/rc.d/init.d/asterisk; generated)
     Active: active (running) since Sun 2024-06-23 23:24:59 IST; 2 weeks 0 days ago
       Docs: man:systemd-sysv-generator(8)
   Main PID: 1224
      Tasks: 39 (limit: 48597)
     Memory: 63.1M
        CPU: 36.087s
     CGroup: /system.slice/asterisk.service
             ├─1221 /bin/sh /usr/sbin/safe_asterisk
             └─5288 /usr/sbin/asterisk -f -vvvg -c

Jun 23 23:24:59 Linuxhelp systemd[1]: Starting LSB: Asterisk PBX...
Jun 23 23:24:59 Linuxhelp asterisk[1140]: Starting asterisk:
Jun 23 23:24:59 Linuxhelp systemd[1]: asterisk.service: Can't open PID file /run/asterisk/asterisk.pid (yet>
Jun 23 23:24:59 Linuxhelp systemd[1]: asterisk.service: Supervising process 1224 which is not our child. We>
Jun 23 23:24:59 Linuxhelp systemd[1]: Started LSB: Asterisk PBX.
Jun 23 23:25:54 Linuxhelp systemd[1]: /run/systemd/generator.late/asterisk.service:30: PIDFile= references >
Jun 23 23:26:17 Linuxhelp systemd[1]: /run/systemd/generator.late/asterisk.service:30: PIDFile= references >
Jul 08 00:33:58 Linuxhelp systemd[1]: /run/systemd/generator.late/asterisk.service:30: PIDFile= references >

Step 3: Move to the Asterisk directory by using the below command.

[root@Linuxhelp ~]# cd /etc/asterisk/

Step 4: Show the endpoints in the pjsip.conf file by using the below command.

[root@Linuxhelp asterisk]# vim pjsip.conf

Step 5: Open extensions.conf file to edit the dialplan using variables by using the below command.

[root@Linuxhelp asterisk]# vim extensions.conf

Step 6: Login to the Asterisk CLI console by using the below command.

[root@Linuxhelp asterisk]# asterisk -rvvvvvvvvvvvvvvv
Asterisk 20.8.1, Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 20.8.1 currently running on Linuxhelp (pid = 5288)

Step 7: Reload the dialplan by using the below command.

Linuxhelp*CLI> dialplan reload
Dialplan reloaded.
[Jul  8 00:57:58] WARNING[6903]: pbx_config.c:1955 pbx_load_config: ==!!== Unknown directive: ringtime at line 3 of extensions.conf -- IGNORING!!!
        > Time to scan old dialplan and merge leftovers back into the new: 0.000002 sec
        > Time to restore hints and swap in new dialplan: 0.000003 sec
        > Time to delete the old dialplan: 0.000002 sec
        > Total time merge_contexts_delete: 0.000007 sec
        > pbx_config successfully loaded 1 contexts (enable debug for details).

Step 8: Exit from the Asterisk CLI by using the below command.

Linuxhelp*CLI> exit
Asterisk cleanly ending (0).
Executing last minute cleanups

Step 9: Again, open the extension.conf to use channel variable by using the below command.

[root@Linuxhelp asterisk]# vim extensions.conf
[internal]
ringtime=20
exten => 167,1,Set(ring=30)
exten => 167,2,Dial(PJSIP/167,${ring})
exten => 167,3,playback()
exten => 167,4,Hangup()
exten => 168,1,Dial(PJSIP/168,${ringtime})

Step 10: Login to the Asterisk CLI Console and reload the dialplan by using the below command.

[root@Linuxhelp asterisk]# asterisk -rvvvvvvvvvvv
Asterisk 20.8.1, Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 20.8.1 currently running on Linuxhelp (pid = 5288)
Linuxhelp*CLI> dialplan reload
Dialplan reloaded.
[Jul  8 01:01:22] WARNING[6969]: pbx_config.c:1955 pbx_load_config: ==!!== Unknown directive: ringtime at line 3 of extensions.conf -- IGNORING!!!
        > Time to scan old dialplan and merge leftovers back into the new: 0.000003 sec
        > Time to restore hints and swap in new dialplan: 0.000003 sec
        > Time to delete the old dialplan: 0.000002 sec
        > Total time merge_contexts_delete: 0.000008 sec
        > pbx_config successfully loaded 1 contexts (enable debug for details).

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps how to use Variables and Global Variables using Asterisk Dialplan Context on Rocky Linux 9.4. Your feedback is much welcome.

Tags:
michael
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What are the variables in Asterisk Dialplan?

A

Variables in Asterisk Dialplan are placeholders used to store and manipulate data during call processing. They can hold values such as phone numbers, extensions, or any other relevant information.

Q

How do I define a local variable in the Asterisk Dialplan?

A

You can define a local variable using the Set application:
exten => 1234,1,Set(MYVAR=Hello)
This sets the variable MYVAR to the value "Hello" for the current call.

Q

How do I use a local variable in the Asterisk Dialplan?

A

You can use a local variable by referencing it with ${} syntax:
exten => 1234,n,NoOp(${MYVAR})
This logs the value of MYVAR.

Q

Can I modify a global variable during a call?

A

Yes, you can modify a global variable during a call using the Set application:
exten => 1234,n,Set(GLOBAL(MYGLOBALVAR)=NewValue)

Q

Can I use both local and global variables in the same dialplan?

A

Yes, you can use both local and global variables in the same dialplan. Ensure to distinguish them properly to avoid conflicts.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Elijah ?
Remote Desktop Connection Has Stopped Working

When accessing my remote machine server using remote desktop on a windows machine I am getting this error

forum (1)

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.