Perl AGI script doesn't work

I had the attached AGI script which worked just fine on the latest trixbox, but when I installed a new server with FreePBX distro the script just gives a congestion signal.

Basically, it transferred a caller to extension 700. It seems like PHP agi scripts work, but none of my perl ones. Is there something you have to do to get these working?

#!/usr/bin/perl

use Asterisk::AGI;
use DBI;

my $AGI = new Asterisk::AGI;
my $dbh = DBI->connect(‘dbi:mysql:airport:localhost’,‘root’,‘passw0rd’);

my %input = $AGI->ReadParse();
my ($text)=@ARGV;

$cardurl = “curl -L -s -o p.txt http://www.test.com/notify/notify.php?fromnumber=".$text." 2>/dev/null”;
system($cardurl);

$AGI->exec(‘Dial’, ‘Local/700’.$number.’@from-internal’);

Is perl installed on the Distro. I am not sure if we include it.

Yes, I believe it is. I see it in /usr/bin/perl and when I run the yum it looks like it is already there.

[root@pbx ~]# yum install perl
Loaded plugins: fastestmirror, kmod
Loading mirror speeds from cached hostfile
Setting up Install Process
Package 4:perl-5.8.8-32.el5_5.2.i386 already installed and latest version
Nothing to do
[root@pbx ~]#

Anything else?

The asterisk user needs to have execute permissions on the file.

Thank you,

but I think that I have already done that :frowning: :

[root@pbx asterisk]# cd /var/lib/asterisk/agi-bin
[root@pbx agi-bin]# ls -la
total 436
drwxrwxr-x 2 asterisk asterisk 4096 Feb 17 17:42 .
drwxrwxr-x 13 asterisk asterisk 4096 Jan 31 02:23 …
-rwxrwxrwx 1 asterisk asterisk 43816 Feb 17 17:39 2257.agi
-rwxrwxrwx 1 asterisk asterisk 1872 Feb 17 12:22 checksound.agi
-rwxrwxrwx 1 asterisk asterisk 2970 Feb 17 12:22 ddns_client.php
-rwxrwxrwx 1 asterisk asterisk 32609 Feb 17 12:22 dialparties.agi
-rwxrwxrwx 1 asterisk asterisk 13303 Feb 17 12:22 directory
-rwxrwxrwx 1 asterisk asterisk 6668 Feb 17 12:22 directory.agi
-rwxrwxrwx 1 asterisk asterisk 10888 Feb 17 12:22 directory.lib.php
-rwxrwxrwx 1 asterisk asterisk 5683 Feb 17 12:22 enumlookup.agi
-rwxrwxrwx 1 asterisk asterisk 1613 Feb 17 12:22 fixlocalprefix
-rwxrwxrwx 1 asterisk asterisk 11025 Feb 17 17:39 jp_reno.agi
-rwxrwxrwx 1 asterisk asterisk 14530 Feb 17 17:39 jukebox.agi
-rwxrwxrwx 1 asterisk asterisk 614 Feb 17 17:39 kioskdial.agi
-rwxrwxrwx 1 asterisk asterisk 2003 Feb 17 12:22 list-item-remove.php
-rwxrwxrwx 1 asterisk asterisk 582 Feb 17 12:22 LoadLicenseIfExists.php
-rwxrwxrwx 1 asterisk asterisk 168 Feb 17 17:40 park701.agi
-rwxrwxrwx 1 asterisk asterisk 168 Feb 17 17:40 park702.agi
-rwxrwxrwx 1 asterisk asterisk 168 Feb 17 17:40 park703.agi
-rwxrwxrwx 1 asterisk asterisk 168 Feb 17 17:40 park704.agi
-rwxrwxrwx 1 asterisk asterisk 398 Feb 17 17:40 parkbilling.agi
-rwxrwxrwx 1 asterisk asterisk 1750 Feb 17 19:21 parkcyrus.agi
-rwxrwxrwx 1 asterisk asterisk 396 Feb 17 17:40 parkother.agi
-rwxrwxrwx 1 asterisk asterisk 23976 Feb 17 17:40 parksac.agi
-rwxrwxrwx 1 asterisk asterisk 396 Feb 17 17:40 parksales.agi
-rwxrwxrwx 1 asterisk asterisk 394 Feb 17 17:40 parksst.agi
-rwxrwxrwx 1 asterisk asterisk 10262 Feb 17 12:22 pbdirectory
-rwxrwxrwx 1 asterisk asterisk 31772 Jan 31 02:38 phpagi-asmanager.php
-rwxrwxrwx 1 asterisk asterisk 65902 Jan 31 02:38 phpagi.php
-rwxrwxrwx 1 asterisk asterisk 3657 Feb 17 12:22 queue_devstate.agi
-rwxrwxrwx 1 asterisk asterisk 21211 Feb 17 12:22 sql.php
-rwxrwxrwx 1 asterisk asterisk 11704 Feb 17 17:40 sst_park_001.agi
-rwxrwxrwx 1 asterisk asterisk 2905 Feb 17 12:22 update_license.php
-rwxrwxrwx 1 asterisk asterisk 18634 Feb 17 12:22 user_login_out.agi
[root@pbx agi-bin]# pwd
/var/lib/asterisk/agi-bin
[root@pbx agi-bin]#

I bet your issue is you are hard coding the MySQL password and FreePBX Distro does not use a standard password for MySQL. You need to put your MySQL password in their.

I tried removing the MySQL lines all together same error just get congestion.

No it needs to get into mysql. What I am saying is you have defined your password for the mysql root user as passw0rd. Is that the password for the mysql root user???

I don’t think MySQL is the problem, and I tested that connection screen in phpMyAdmin and that is correct (I changed the password to that so it would match my old trixbox stuff). And yes it is the password, but I don’t have the server externally accessible.

I am also not sure why it would need MySQL, the following AGI script I just tested on my old trixbox and it works perfectly but when I test on my freepbx distro I just get congestion:

#!/usr/bin/perl

use Asterisk::AGI;
use DBI;

my $AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();
my ($text)=@ARGV;

$cardurl = “curl -L -s -o p.txt http://www.xyz123.com/notify/notifier.php?fromnumber=".$text." 2>/dev/null”;
system($cardurl);

$AGI->exec(‘Dial’, ‘Local/700’.$number.’@from-internal’);

When I try on FreePBX here is the log:
Connected to Asterisk 1.8.7.1 currently running on pbx (pid = 2948)
Verbosity is at least 3
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
– Executing [9004@from-internal:1] Answer(“SIP/2202-00000006”, “”) in new stack
– Executing [9004@from-internal:2] AGI(“SIP/2202-00000006”, “parkcyrus.agi,2202”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/parkcyrus.agi
– <SIP/2202-00000006>AGI Script parkcyrus.agi completed, returning 0
– Executing [9004@from-internal:3] Hangup(“SIP/2202-00000006”, “”) in new stack
== Spawn extension (from-internal, 9004, 3) exited non-zero on ‘SIP/2202-00000006’
– Executing [h@from-internal:1] Hangup(“SIP/2202-00000006”, “”) in new stack
== Spawn extension (from-internal, h, 1) exited non-zero on ‘SIP/2202-00000006’

Well we use asterisk 1.8 and Trixbox does not. I might be something different that has to change in your code. You can turn on agi debugging in asterisk and see if that helps. AGI’s can be fun to debug.

Thank you for your thoughts, I re-wrote a very simple AGI script that just plays back a file:

#!/usr/bin/perl
use Asterisk::AGI;
my $AGI = new Asterisk::AGI;
#$AGI->exec(‘Playback’, ‘/var/lib/asterisk/sounds/custom/reno_welcome’);

and here is the debug log (still just congestion) – is there something I have to do to enable perl AGI scripts or something, please help!! I don’t want to have to go back to trixbox :frowning:

pbxCLI> agi set debug on
AGI Debugging Enabled
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
– Executing [9004@from-internal:1] Answer(“SIP/2201-00000067”, “”) in new stack
– Executing [9004@from-internal:2] AGI(“SIP/2201-00000067”, “parkcyrus.agi,2201”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/parkcyrus.agi
<SIP/2201-00000067>AGI Tx >> agi_request: parkcyrus.agi
<SIP/2201-00000067>AGI Tx >> agi_channel: SIP/2201-00000067
<SIP/2201-00000067>AGI Tx >> agi_language: en
<SIP/2201-00000067>AGI Tx >> agi_type: SIP
<SIP/2201-00000067>AGI Tx >> agi_uniqueid: 1329588300.123
<SIP/2201-00000067>AGI Tx >> agi_version: 1.8.7.1
<SIP/2201-00000067>AGI Tx >> agi_callerid: 2201
<SIP/2201-00000067>AGI Tx >> agi_calleridname: device
<SIP/2201-00000067>AGI Tx >> agi_callingpres: 0
<SIP/2201-00000067>AGI Tx >> agi_callingani2: 0
<SIP/2201-00000067>AGI Tx >> agi_callington: 0
<SIP/2201-00000067>AGI Tx >> agi_callingtns: 0
<SIP/2201-00000067>AGI Tx >> agi_dnid: 9004
<SIP/2201-00000067>AGI Tx >> agi_rdnis: unknown
<SIP/2201-00000067>AGI Tx >> agi_context: from-internal
<SIP/2201-00000067>AGI Tx >> agi_extension: 9004
<SIP/2201-00000067>AGI Tx >> agi_priority: 2
<SIP/2201-00000067>AGI Tx >> agi_enhanced: 0.0
<SIP/2201-00000067>AGI Tx >> agi_accountcode:
<SIP/2201-00000067>AGI Tx >> agi_threadid: -1219433584
<SIP/2201-00000067>AGI Tx >> agi_arg_1: 2201
<SIP/2201-00000067>AGI Tx >>
– <SIP/2201-00000067>AGI Script parkcyrus.agi completed, returning 0
– Executing [9004@from-internal:3] Hangup(“SIP/2201-00000067”, “”) in new stack
== Spawn extension (from-internal, 9004, 3) exited non-zero on ‘SIP/2201-00000067’
– Executing [h@from-internal:1] Hangup(“SIP/2201-00000067”, “”) in new stack
== Spawn extension (from-internal, h, 1) exited non-zero on 'SIP/2201-00000067’
pbx
CLI>

Sorry, the script is this:

#!/usr/bin/perl
use Asterisk::AGI;
my $AGI = new Asterisk::AGI;
$AGI->exec(‘Playback’, ‘/var/lib/asterisk/sounds/custom/reno_welcome’);

Actually, the problem is probably not the perl script but the way you are calling it.

You need to share your dialplan config.

Certainly you don’t want to go back to trixbox, the FreePBX is is 8 versions old and the project is abandoned.

You can use Asterisk 1.6 (the version trix 2.8 uses) with FreePBX 2.10.

You need to post a full excerpt of your dial plan that calls the script and all surrounding logic. Also a copy of the full log with both verbosity and debug cranked up.

I would not post the log in forum, post it at pastebin.ca and provide a link.

Here is the dialplan, this is in extensions_custom.conf and this is exactly what I used on Trixbox:

[from-internal-custom]
exten => 9004,1,Answer
exten => 9004,2,AGI(parkcyrus.agi,${CALLERID(number)});
exten => 9004,3,Hangup

And here is the log (it is short):

pbxCLI> core set verbose 99999999999
Verbosity was 3 and is now 2147483647
> doing dnsmgr_lookup for ‘inbound23.vitelity.net
> doing dnsmgr_lookup for ‘inbound23.vitelity.net
[2012-02-18 14:59:01] NOTICE[13473]: chan_sip.c:20192 handle_response_peerpoke: Peer ‘2701’ is now Reachable. (87ms / 2000ms)
pbx
CLI> agi set debug on
AGI Debugging Enabled
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
– Executing [9004@from-internal:1] Answer(“SIP/2202-0000007d”, “”) in new stack
– Executing [9004@from-internal:2] AGI(“SIP/2202-0000007d”, “parkcyrus.agi,2202”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/parkcyrus.agi
<SIP/2202-0000007d>AGI Tx >> agi_request: parkcyrus.agi
<SIP/2202-0000007d>AGI Tx >> agi_channel: SIP/2202-0000007d
<SIP/2202-0000007d>AGI Tx >> agi_language: en
<SIP/2202-0000007d>AGI Tx >> agi_type: SIP
<SIP/2202-0000007d>AGI Tx >> agi_uniqueid: 1329605956.145
<SIP/2202-0000007d>AGI Tx >> agi_version: 1.8.7.1
<SIP/2202-0000007d>AGI Tx >> agi_callerid: 2202
<SIP/2202-0000007d>AGI Tx >> agi_calleridname: device
<SIP/2202-0000007d>AGI Tx >> agi_callingpres: 0
<SIP/2202-0000007d>AGI Tx >> agi_callingani2: 0
<SIP/2202-0000007d>AGI Tx >> agi_callington: 0
<SIP/2202-0000007d>AGI Tx >> agi_callingtns: 0
<SIP/2202-0000007d>AGI Tx >> agi_dnid: 9004
<SIP/2202-0000007d>AGI Tx >> agi_rdnis: unknown
<SIP/2202-0000007d>AGI Tx >> agi_context: from-internal
<SIP/2202-0000007d>AGI Tx >> agi_extension: 9004
<SIP/2202-0000007d>AGI Tx >> agi_priority: 2
<SIP/2202-0000007d>AGI Tx >> agi_enhanced: 0.0
<SIP/2202-0000007d>AGI Tx >> agi_accountcode:
<SIP/2202-0000007d>AGI Tx >> agi_threadid: -1219433584
<SIP/2202-0000007d>AGI Tx >> agi_arg_1: 2202
<SIP/2202-0000007d>AGI Tx >>
– <SIP/2202-0000007d>AGI Script parkcyrus.agi completed, returning 0
– Executing [9004@from-internal:3] Hangup(“SIP/2202-0000007d”, “”) in new stack
== Spawn extension (from-internal, 9004, 3) exited non-zero on ‘SIP/2202-0000007d’
– Executing [h@from-internal:1] Hangup(“SIP/2202-0000007d”, “”) in new stack
== Spawn extension (from-internal, h, 1) exited non-zero on 'SIP/2202-0000007d’
pbx*CLI>

Thank you for your help!

After much messing around I had the stroke of genius to try and execute the script from the shell (./parkcyrus.agi) and see what happened, on trixbox it did nothing and on FreePBX it gave a bunch of errors.

If anyone else has this problem here is what you do, try and run it and you will see files are in the wrong directory.

You need to move AGI.pm and Asterisk.pm to /usr/lib/perl5/5.8.8/Asterisk and /usr/lib/perl5/5.8.8 respectively from /root/asterisk-perl-1.03/lib/ and you will be in business!

So no problem with the dialplan or mysql or anything. Thank you very much Skyking and Tony for the help though, I do appreciate it.

No problem, this is a great example of how difficult it is to offer forum support on custom apps. We would have found it in a couple of minutes in front of the console.

On FreePBX (Latest) - installed Asterisk-Perl, but cannot get Asterisk::AGI to work. Working fine on an older Asterisk 1.6 installation. Not sure what I’ve done/am doing incorrectly. AGI debug not helping in this situation either…

Ideas on where to look?
Thanks,
PB