Can't get custom perl AGI scripts to work

Discussion in 'General' started by wiseoldowl, Aug 20, 2008.

  1. wiseoldowl

    Aug 19, 2008
    Likes Received:
    We just switched from another Asterisk/FreePBX distribution to Elastix and although I'm generally impressed, I have one perplexing problem I can't seem to overcome. I have some custom perl scripts in /var/lib/asterisk/agi-bin that do things like play weather information, etc. These basically download a "podcast" and play it to the caller. The script is designed to give feedback on the CLI as it operates, so if some particular command isn't working you can see where the problem is. These scripts ran great on the old system but appear to not even get started on the new. I have tried obvious things like making sure that requisite perl modules are installed, and checking the permissions on the files (they are readable and executable by everyone) but they don't work. I'm thinking it's probably something simple and maybe even obvious, but it isn't obvious to me right now. I know these scripts work fine in a different distribution (one we tested briefly and abandoned because calls simply weren't completing reliably) but for some reason Elastix just ignores them.

    Here's a typical CLI display when attempting to call the number that should play the weather podcast (sorry about the smilies - if I use the code tags it gets rid of them but also seems to run all the lines together):

    -- Executing [*28@from-internal:1] NoOp("SIP/250-09d79da0", "Running miscapp 2: Weather Forecast") in new stack
    -- Executing [*28@from-internal:2] Goto("SIP/250-09d79da0", "custom-weather|*28|1") in new stack
    -- Goto (custom-weather,*28,1)
    -- Executing [*28@custom-weather:1] NoOp("SIP/250-09d79da0", "Entering Custom Context: Weather") in new stack
    -- Executing [*28@custom-weather:2] Ringing("SIP/250-09d79da0", "") in new stack
    -- Executing [*28@custom-weather:3] AGI("SIP/250-09d79da0", "weather.agi") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/weather.agi
    -- AGI Script weather.agi completed, returning 0
    -- Executing [*28@custom-weather:4] GotoIf("SIP/250-09d79da0", "1?app-blackhole|hangup|1:|return|1") in new stack
    -- Goto (app-blackhole,hangup,1)
    -- Executing [hangup@app-blackhole:1] NoOp("SIP/250-09d79da0", "Blackhole Dest: Hangup") in new stack
    -- Executing [hangup@app-blackhole:2] Hangup("SIP/250-09d79da0", "") in new stack
    == Spawn extension (app-blackhole, hangup, 2) exited non-zero on 'SIP/250-09d79da0'

    Note that it appears to launch the AGI script, but there is no display of any of the lines from within the script - it appears the script immediately returns control to the code in extensions_custom.conf, without actually doing anything. Normally if there's a problem with the script itself, you see lines showing the progress of the script until it fails. This script isn't doing anything, which is what makes me think either permissions or a missing perl module, but as far as I can tell neither seems to be the problem. I'm simply perplexed as to why it won't work under Elastix when it's worked fine under two other distros.
  2. wiseoldowl

    Aug 19, 2008
    Likes Received:
    Had a chance to do some further testing on this and discovered that my perl AGI scripts seem to not like this:

    use Asterisk::AGI;

    When I try to use that module (which apparently is present and usable in other distributions), the script won't run. Just the presence of that one statement in the script is enough to cause the entire script to fail, even if I don't actually try to do anything with that module.

    Of course, that is in nearly every one of my scripts. Not being exactly what you would call a perl expert I'm not quite sure where to go from here, particularly since Webmin indicates that Asterisk::AGI is on my system - if I use Webmin to look at the installed Perl modules, I see one called "Asterisk", version 0.09, and if I click on that it shows this:

    Module information
    Module name Asterisk 0.09 Description None available
    Installed on Sun Aug 17 21:48:00 2008 Module file /usr/lib/perl5/vendor_perl/5.8.8/
    Installed from RPM package asterisk-perl
    Submodules Asterisk::AGI | Asterisk::Manager | Asterisk::Outgoing | Asterisk::QCall | Asterisk::Voicemail

    So the weird part is that Asterisk::AGI seems to be installed, but my scripts refuse to run if I try to use it!

    EDIT: Okay, part of it was a permissions issue - the subdirectory /usr/lib/perl5/vendor_perl/5.8.8/Asterisk had improper permissions (compare to the other directories at that level) - once I set the execute bit for all levels then the script started partially working. Then I discovered that lame is not installed - after installing it by following the instructions given by saleh in another thread, I was able to install lame and now it works. So for anyone else having this problem, the bottom line is:

    • Make sure that the directory /usr/lib/perl5/vendor_perl/5.8.8/Asterisk (or whatever is used for the Asterisk perl modules on your system) is executable by all users - check the permissions!
    • If your script calls lame, make sure that lame is actually installed - see the thread at
    • Also if your script calls lame, make sure it's an explicit path reference to lame, e.g. /usr/bin/lame (not just lame) - use which lame from a command prompt if you are not sure of the path (or whether lame is installed at all!)
  3. mosier

    Jul 17, 2011
    Likes Received:
    For not being a work guy you did a great job at fixing the problem. I had a feeling it was permissions. So what do all the scripts do? Im interested in checking them out. Any chance you could post them?


Share This Page