2

Ok, so I have a ruby script that grabs some data from FM Server and returns a tuple. I had to do this because there's no good perl FM module that I'm aware of.

[test.pl]

$ret = `ruby /root/rfm-query.rb $cid`;
@extens = split(/,/, $ret, 2);
print "DIAL SIP/$extens[0]";

So when I run this it will print "DIAL SIP/215" as expected but when using the same code in an Asterisk AGI script and using $extens[0] it always returns nothing.

#!/usr/bin/env perl
use Asterisk::AGI;
$|=1;

$AGI = new Asterisk::AGI;
%input = $AGI->ReadParse();

$cid = substr $input{'callerid'}, 1;
$cid =~ s/\+//g;

$ret = `ruby /root/rfm-query.rb $cid`; #rets nothing
@extens = split(/,/, $ret, 2);

$AGI->exec("DIAL SIP/$extens[0]");

Why does it work in a test script but not in an AGI?

3
  • Does Net::FileMaker do what you're looking for? Commented Jun 3, 2011 at 19:32
  • I looked at Net::FileMaker and the documentation seems to suck. I'm not really sure if it does what I need or not. Commented Jun 3, 2011 at 19:47
  • @mu Yes they are both being ran as the same user. I can't tell you what's in $? when it fails because I can't figure out how to get the AGI script to output text to the Asterisk console. Commented Jun 3, 2011 at 19:48

1 Answer 1

2

I'm not sure what an Asterix AGI script is, but if its anything like CGI, where your code is being run by a server, then its probably running as a different user as you. Hopefully it is and not root and it probably can't read /root/rfm-query.rb.

You can check this by trying to open and print the file for reading.

my $rfm_query_file = "/root/rfm-query.rb";
open my $fh, "<", $rfm_query_file or die "Cant open $rfm_query_file: $!";

(Also, shame on you if you're developing and testing code as root.)

Sign up to request clarification or add additional context in comments.

5 Comments

Asterisk runs with it's own user so I tried placing the ruby script into that user's directory and it still doesn't work. I don't understand why it refuses to work properly when ran via AGI but works fine when ran as a regular perl script on the CLI.
Could the script read the file? Also, the STDERR from the script is probably going into a log file somewhere and you're not seeing it. You can capture it with ruby /root/rfm-query.rb $cid 2>&1. Its also possible that $cid is not what you think it is. It might have spaces and shell meta-characters which is causing the command line to be incorrect.
I don't know because I can't get it to output anything at all on the asterisk console for me to see.
If $cid wasn't what I was expecting then why does it work in the other script which contains the same code?
Ok thanks man. Adding 2>&1 showed me what the problem is. It wasn't able to find the ruby script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.