[Freeswitch-users] problem exporting variables from shellsctipt not working

Michael Collins msc at freeswitch.org
Sun May 15 01:01:09 MSD 2011


ZOMG I wish I was blind like Thomas, Covici, and DelphiWorld so I wouldn't
have to read this thread any more!! :P </rant>

What you want to do is not possible directly from the dialplan, or even from
the console. There are probably several ways to address this problem. Since
I like Lua I thought a simple demonstration using a small amount of Lua to
get what you want would be good. Here is a generic Lua script that you can
call from the command line and feed it an argument which it will in turn
execute as a system call, then return the system's output:

-- sys_call.lua
--
-- simple read from pipe
-- Be sure to escape spaces in the argument cuz I was to lazy to parse args
properly...



cmd = argv[1];
freeswitch.consoleLog("DEBUG","sys_call.lua call with arg: '" .. cmd ..
"'\n");

f = assert (io.popen(cmd));
res_data = '';
for line in f:lines() do
  res_data = res_data .. line .. "\n";
end



stream:write(res_data);


freeswitch.consoleLog("DEBUG","sys_call.lua result: '" .. res_data ..
"'\n");

f:close();

Now you can go to fs_cli and do things like:
lua sys_call.lua ls\ -l

Now, Thomas, in your specific case you are trying to capture input from the
caller and compare that to the output from the command: date -d <date
argument> +%s and you have a script that does this comparison for you. To
call your shell script from the command line with my Lua script would be
this:

lua sys_call.lua datechk.sh\ <date value argument>

(Don't forget to put a backslash in front of the space character.) To do
this in the dialplan you need to use the special notation that lets you
execute an API call using the "set" dialplan application. Let's say the
input you capture from your caller is in variable ${nr}. You can set a new
channel variable that captures the output of your script:

<action application="set" data="my_result=${lua sys_call.lua datechk.sh\
${nr}}"/>

Now you have a new channel variable ${my_result} that contains the result of
the system call to your date script. From here you will need use the
dialplan "transfer" or "execute_extension" in order to do something with the
result. I recommend that you create a separate dialplan context and transfer
the call into that context for further processing.

<action application="transfer" data="${my_result} XML handle_date_test"/>

Then your new context could be something like this:
<context name="handle_date_test">
  <extension name="date match is good">
    <condition field="destination_number" expression="^good\s*$">
      <action application="log" data="INFO date matches, do stuff in action
tags..."/>
      <anti-action application="log" data="INFO date does not match, handle
this in anti-action tags..."/>
    </condtion>
  </extension>
</context>

For all of this to work you will have to change your script so that if the
dates match then the script will echo "good" to the console. If the dates do
not match then your script will need to echo anything other than "good".

Thomas, I respect you for trying so hard to make this work with only a
braille reader and in a language that is not your first. Keep up the good
work. I hope this helps.

-MC

On Sat, May 14, 2011 at 5:11 AM, Thomas Hoellriegel <admin at blindi.net>wrote:

> Am 14.05.11 um 01:37 schrieb Madovsky:
>
>
>  I think you have to escape the $ 3 times
>>
> I don.t no. $3? I like to export the variable: dateerror  from the
> shellscript in my fs dialplan, to make a selection from condidion field.
>
>> \\\${nir}
>>
> what is the syntax in the dialplan?
> thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20110514/133ecc50/attachment.html 


More information about the FreeSWITCH-users mailing list