@navaismo,
I tried with the code below and didn’t work. I will try your and tell the result:
[code]#!/usr/bin/php -q
<?php
$no=preg_replace("#[^0-9]#","",$agi->request[agi_callerid]);//remove any non numeric characters
/*
connect to "asterisk" database in mysql; in this case only 1 table "clients"
column telsearch contains concatenated mobile, home and work numbers
e.g. 0121777887207986238123
script will search for caller number within this field
*/
$db = 'qstats';
$dbuser = 'root';
$dbpass = 'dbpass';
$dbhost = 'localhost';
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db("$db"); //or die("could not open database");
$row=mysql_query("select qagent from dbtable where uniqueid=$argv[2] and qevent=4");
if (mysql_num_rows($row)==1&&strlen($no)>4){//if found number and number greater than 4 digits to avoid 3 digit internal extensions
$row=mysql_fetch_array($row);
if ($row[title]) $name .= $row[title]." ";
if ($row[firstname]) $name .= $row[firstname]." ";
if ($row[lastname]) $name .= $row[lastname];
}
else $name=$agi->request[agi_callerid];//else set calleridname to callerid number
#$agi->set_variable("cid", $name);
$ip=array(52=>'192.168.2.2.26',53=>'192.168.2.55',54=>'192.168.2.28',55=>'192.168.2.24',56=>'192.168.2.22',58=>'192.168.2.21');
$url_string = 'echo "'.$argv[1].'" | nc -w 1 '.$ip[$name].' 10629';
echo $url_string;
shell_exec($url_string);
[/code]
I will post the results.
Thanks!!!
Change the Verbose($MSQL) for Verbose(“this is the result of query <<${MSQL}>>”,3);
and send your query with:
$link = mysql_connect($host,$user,$pass) or die(mysql_error());
$MSQL=mysql_query("SELECT qagent FROM dbtable WHERE uniqueid=$id AND event=4",$link) or die(mysql_error());
My problem is that when I call a mysql query from Asterisk, it doesn’t work, shows nothing.
And when I run the script from out Asterisk enviorment it works fine.
The problem it’s here:
Asterisk -> Shell Script(AGI) -> Mysql
When its:
Shell Script - Mysql - there is no problem!!!
Guys, I still have this f*** problem!
I wrote in PHP and happens the same thing, take a look at the script.
Remembering that if I run it from the shell enviorment, it runs ok.
Let’s remeber that the script it’s ok, because I can run it from the shell:
asterisk:/var/lib/asterisk/agi-bin# ./teste2.php a 1314977992.32870
And the log:
asterisk:/var/lib/asterisk/agi-bin# cat /home/felipe/log_php
Id do agente: 56
Comando executado: echo a | nc -w 1 192.168.2.22 10629
And lets remember that the problem is when Asterisk calls the script. This is the output log
dbcpaulista:/var/lib/asterisk/agi-bin# cat /home/felipe/log_php
Id do agente:
Comando executado: echo 45063119 | nc -w 1 10629
As you can see at the code, the $agente[$vq] should be the IP address fo the agent. But when it runs from Asterisk, it doesn’t work. There isn’t another information at the system logs, messages, fulls, etc.
Two things:
First, remove the empty line, after the #! line, as php outputs an empty line. That’s just to avoid the [Sep 5 15:22:37] VERBOSE[30539] res_agi.c: <DAHDI/33-1>AGI Tx >> 510 Invalid or unknown command.
Second: there’s obviously something wrong with either your query or the result, because PHP reports undefined index at line 54, which is for the $agente[$vq]. This error means, that the agente array doesn’t have an index of the value of $vq. Are you sure you’re connecting to MySQL server correctly? mysql_connect(), when connecting to “localhost”, uses either the php.ini configured socket, the .my.cnf configured socket for the user it’s running as, /etc/my.cnf or, as last resort, the build time configured/detected socket. I suspect you have an issue connecting to MySQL (might even be connecting to the wrong server, if you have multiple). On the other hand it doesn’t die at the mysql_select_db(), so this query has to be successful. The next thing would be some kind of an error with the query. Is this the real query you have posted? If so I think you should escape the “table” with backquotes, as it’s a keyword in MySQL. If not please post the real query and the asterisk command you’re using to invoke the AGI.