[asterisk-users] SHELL() function Asterisk 13 - can only accept one paramter in string?

Stefan Viljoen viljoens at verishare.co.za
Fri Jul 27 09:24:59 CDT 2018


With thanks to Ludovic Gasc

---

Turns out there is nothing wrong with the SYSTEM() or SHELL() dialplan functions in Asterisk 13.22.0.

After several hours of painstaking debugging, the problem turned out to be a linefeed (\n character, 0x0a hex) in the first parameter passed from Asterisk to the bash script in the call to the SYSTEM() or SHELL() applications.

Ludovic's suggestion to try AGI revealed the issue - it has nothing to do with AGI or SYSTEM() but rather my data for one parameter passed through system containing a linefeed (\n)....

E. g. I was calling this:

same=>n,System(/usr/src/verdi/bash/verdiLogIncomingCall.sh NA ${curIncAccCode} ${sourceChannel} IN ${CHANNEL} ${numbersource} ApiLogIncomingCall.java 1)

but

${curIncAccCode}

appeared to contain a UUID I generate in a JAVA application.

In fact it contained

uuidtexthere\n

instead of just

uuidtexthere

E. g. it had an appended \n (hex 0a) linefeed character appended.

My script that generated this UUID looked like this:

---
#!/bin/bash
function jsonval {
    temp=`echo $jsonResult | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g'`
    echo ${temp##*|}
}

baseUrl=http://127.0.0.1/api/getVerdiUUID

jsonResult=$(curl --connect-timeout 16 --max-time 32 -s -X GET $baseUrl)

uuid=`jsonval`

echo $uuid
---

So all that I actually needed to fix was to change

echo $uuid

to

echo -n $uuid

and all my problems were solved, SYSTEM() started working perfectly everywhere in the dialplan as the script wasn't emitting a trailing \n anymore.

So the germane difference between Asterisk 1.8 and Asterisk  13 / 12 / 11 / 10 in this case was that SYSTEM() and SHELL() in the later versions are sensitive to \n being passed in inside any of the Asterisk variables passed into those applications' parameter string.

Maybe this helps somebody else.

Regards

Stefan




More information about the asterisk-users mailing list