Execute shell command in a AGI Script


I’m trying to use the weather_metar agi script that I found on the wiki. After many hours to figure out why it’s not working, I came to the conclusion that the bash command were not executed. Here is a copy of the script :


weather_metar.agi V-0.1a

Writen by Marat Gulevich <gool (at) gool.dyndns.biz> JAN 2006

. /var/lib/asterisk/agi-bin/sh-agi.inc
WEATHER=$(metar -d $1)
T1=$(echo $WEATHER | cut -d “:” -f10 | sed ‘s/ Dewpoint/,/’ | sed ‘s/C/celsium degree/’)
T2=$(echo $WEATHER | cut -d “:” -f14 | sed ‘s/ //’)
sh_agi_log "$SP"
sh_agi_cmd EXEC Festival “$SP”

To make a short story, if I enter manually each line of this script in a terminal, everything is fine and the variable take the value they are supposed to. But using the AGI, festival report a error : argument must be a string. The problem is that “SP” is a string with value like : 11 Celcius. So if I replace $SP by a string, everything is fine.

How can I make sure the script is entierely executed. If I run agi debug in the CLI, It do not show me detailled debug about the script.

Another thing I tought about is to execute the script and stock the result in a environnement variable. The launch Festival with the ${ENV(VARNAME)}. I tried to create a env variable using “export name=value” in FC4. Then the env command show me the varaible. But in Asterisk, If I call noop(${ENV(VARNAME)}), I get an empty string.

Anyone could help ?