• 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 AGI Script in Asterisk on Oracle Linux 9.3

  • 00:39 cat /etc/os-release
  • 01:00 systemctl status asterisk.service
  • 01:23 cd /var/lib/asterisk/agi-bin/
  • 01:35 ll
  • 01:44 vim demoagi
  • 02:41 chmod +x demoagi
  • 03:02 cd /etc/asterisk/
  • 03:19 vim extensions.conf
  • 03:42 asterisk -rvvvvvvvvvvvvvvvvvvv
  • 03:53 dialplan reload
{{postValue.id}}

To Use AGI Script In Asterisk On Oracle Linux 9.3

Introduction:

The Asterisk Gateway Interface (AGI) serves as a connection point between the Asterisk dialplan and an external program seeking to interact with a channel within the dialplan. This interface typically operates in a synchronous manner, meaning that actions performed on a channel from an AGI block will not conclude until the action has been fully executed.

Procedure:

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

[root@linuxhelp ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.3"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.3"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.3"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:3:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.3
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.3

Step 2: I have already installed Asterisk on my Oracle Linux machine, Now I am going to check the status of the Asterisk by using the below command

[root@linuxhelp ~]# systemctl status asterisk.service
● asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/rc.d/init.d/asterisk; generated)
     Active: active (running) since Fri 2024-05-31 13:45:37 IST; 7min ago
       Docs: man:systemd-sysv-generator(8)
    Process: 6338 ExecStart=/etc/rc.d/init.d/asterisk start (code=exited, status=0/SUCCESS)
   Main PID: 6367 (asterisk)
      Tasks: 38 (limit: 21739)
     Memory: 37.2M
        CPU: 4.392s
     CGroup: /system.slice/asterisk.service
             ├─6365 /bin/sh /usr/sbin/safe_asterisk
             └─6367 /usr/sbin/asterisk -f -vvvg -c

May 31 13:45:37 linuxhelp systemd[1]: Starting LSB: Asterisk PBX...
May 31 13:45:37 linuxhelp asterisk[6338]: Starting asterisk:
May 31 13:45:37 linuxhelp systemd[1]: asterisk.service: Can't open PID file /run/asterisk/asterisk.pid (yet?) after start: Operation not permitted
May 31 13:45:37 linuxhelp systemd[1]: asterisk.service: Supervising process 6367 which is not our child. We'll most likely not notice when it exit>
May 31 13:45:37 linuxhelp systemd[1]: Started LSB: Asterisk PBX.

Step 3: Now change the directory to Asterisk default AGI directory by using the below command

[root@linuxhelp ~]# cd /var/lib/asterisk/agi-bin/

Step 4: List the directory by using the below command

[root@linuxhelp agi-bin]# ll
total 0

Step 5: Create a new file using vim editor by using the below command

[root@linuxhelp agi-bin]# vim demoagi
Add those following command
#!/usr/bin/bash
echo "SET VARIABLE rep $1"
echo "SET VARIABLE exten $2"

Step 6: Now give the execute permission to the file by using the below command

[root@linuxhelp agi-bin]# chmod +x demoagi

Step 7: Change the directory to the asterisk configuration directory by using the below command

[root@linuxhelp agi-bin]# cd /etc/asterisk/

Step 8: Now edit the extensions.conf file to change the dialplan by using the below command

[root@linuxhelp asterisk]# vim extensions.conf
Add those Following Command
[internal]
exten => _XXX,1,AGI(demoagi,3,${EXTEN})
exten => _XXX,n,NoOp(Dialing Extension is =============== ${exten} and the repeat is ========== ${rep})
exten => _XXX,n,Set(repeat=${rep})
exten => _XXX,n(repeat),Playback(hello)
exten => _XXX,n,Set(repeat=$[ ${repeat} - 1 ])
exten => _XXX,n,GotoIf($[ ${repeat} > 0]?repeat:continue)
exten => _XXX,n(continue),Dial(PJSIP/${exten})

Step 9: Login to the Asterisk CLI mode by using the below command

root@linuxhelp asterisk]# asterisk -rvvvvvvvvvvvvvvvvvvv
Asterisk 20.5.0, 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.5.0 currently running on linuxhelp (pid = 8900)
linuxhelp*CLI>

Step 10: After the changes in the extensions.conf file, need to reload the dialplan by using the below command

linuxhelp*CLI> dialplan reload
Dialplan reloaded.
    -- Including switch 'DUNDi/e164' in context 'ael-dundi-e164-switch'
    -- Time to scan old dialplan and merge leftovers back into the new: 0.000212 sec
    -- Time to restore hints and swap in new dialplan: 0.000006 sec
    -- Time to delete the old dialplan: 0.000054 sec
    -- Total time merge_contexts_delete: 0.000272 sec
    -- pbx_config successfully loaded 22 contexts (enable debug for details).

Step 11: Now try to make a call by using the Zoiper and microsip software Snap1

Step 12: Now make call from 167 to 168 Snap 2

Output:
Executing [168@internal:1] AGI("PJSIP/167-00000000", "demoagi,3,168") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/demoagi
    -- <PJSIP/167-00000000>AGI Script demoagi completed, returning 0
    -- Executing [168@internal:2] NoOp("PJSIP/167-00000000", "Dialing Extension is =============== 168 and the repeat is ========== 3") in new stack
    -- Executing [168@internal:3] Set("PJSIP/167-00000000", "repeat=3") in new stack
    -- Executing [168@internal:4] Playback("PJSIP/167-00000000", "hello") in new stack
       > 0x7f1a88011aa0 -- Strict RTP learning after remote address set to: 192.168.6.101:8000
       > 0x7f1a88011aa0 -- Strict RTP switching to RTP target address 192.168.6.101:8000 as source
    -- <PJSIP/167-00000000> Playing 'hello.ulaw' (language 'en')
    -- Executing [168@internal:5] Set("PJSIP/167-00000000", "repeat=2") in new stack
    -- Executing [168@internal:6] GotoIf("PJSIP/167-00000000", "1?repeat:continue") in new stack
    -- Goto (internal,168,4)
    -- Executing [168@internal:4] Playback("PJSIP/167-00000000", "hello") in new stack
    -- <PJSIP/167-00000000> Playing 'hello.ulaw' (language 'en')
    -- Executing [168@internal:5] Set("PJSIP/167-00000000", "repeat=1") in new stack
    -- Executing [168@internal:6] GotoIf("PJSIP/167-00000000", "1?repeat:continue") in new stack
    -- Goto (internal,168,4)
    -- Executing [168@internal:4] Playback("PJSIP/167-00000000", "hello") in new stack
    -- <PJSIP/167-00000000> Playing 'hello.ulaw' (language 'en')
    -- Executing [168@internal:5] Set("PJSIP/167-00000000", "repeat=0") in new stack
    -- Executing [168@internal:6] GotoIf("PJSIP/167-00000000", "0?repeat:continue") in new stack
    -- Goto (internal,168,7)
    -- Executing [168@internal:7] Dial("PJSIP/167-00000000", "PJSIP/168") in new stack
    -- Called PJSIP/168
    -- PJSIP/168-00000001 is ringing
       > 0x7f1a88011aa0 -- Strict RTP learning complete - Locking on source address 192.168.6.101:8000
  == Everyone is busy/congested at this time (1:1/0/0)
    -- Auto fallthrough, channel 'PJSIP/167-00000000' status is 'BUSY'

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to use AGI Script on Asterisk on Oracle Linux 9.3. Your feedback is much welcome.

Tags:
michael
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

Where are AGI scripts stored in Asterisk?

A

AGI scripts often reside in the AGI directory (usually located in /var/lib/asterisk/agi-bin), but you can specify the complete path to the AGI script.

Q

What is the function of AGI in an asterisk?

A

AGI provides an interface between the Asterisk dialplan and an external program that wants to manipulate a channel in the dialplan.

Q

What is the difference between AMI and AGI in asterisk?

A

AMI is third-party control and doesn't appear in the dialplan. AGI is first-party control and always has to appear in the dialplan.

Q

What is the full form of AGI in Asterisk?

A

Asterisk Gateway Interface (AGI) is a software interface and communications protocol for application-level control of selected features of the Asterisk PBX.

Q

How do you restart the Asterisk service?

A

By using the following command you can restart the Asterisk service
# systemctl restart asterisk

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 legeek ?
Installation of the call center module

hello

I wish to install a call center in virtual with issabel, I downloaded the latest version of it , but I don' t arrive to install the call center module in issabel. please help me

thanks!

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.