Shell Command Failing

Trying to run this Shell command to get the domain from the from SIP header:
exten => s,n,Set(UWIPDEST=${SHELL(${SIP_HEADER(From)} | sed -e 's/;.*//' | grep -q "@domain.com" && echo "555.555.555.555" || echo "666.666.666.666")})

39876	[2024-07-08 16:22:50] WARNING[1162][C-000a9f74] pbx_variables.c: Error in extension logic (missing '}')	
39877	[2024-07-08 16:22:50] WARNING[1162][C-000a9f74] pbx_variables.c: Error in extension logic (missing '}')	
39878	[2024-07-08 16:22:50] WARNING[1162][C-000a9f74] pbx_functions.c: Can't find trailing parenthesis for function 'SIP_HEADER(From'?	
39879	[2024-07-08 16:22:50] WARNING[1162][C-000a9f74] pbx_functions.c: Can't find trailing parenthesis for function 'SHELL("Doe, John" <sip:[email protected]>;tag=519e66763d4641ef821705056ba958f'?

I think maybe the issue is because there is a semicolon in the from header, but I am not sure? All I am really trying to do is see is if the from header contains β€˜domain.com’ if it does make the variable ${UWIPDEST} 555.555.555.555, otherwise make it 666.666.666.666.

What am I missing to make this work?

; marks the start of a dialplan comment, and would need to be escaped with \

You should be able to do this without leaving Asterisk.

1 Like

Something hideous like this:

${CUT(${CUT(${PJSIP_HEADER(read,From)},@,2)},>,1)}

1 Like

How do I do this as that part of the dialplan is a variable? There will always be a semicolon, but it’s not static in location.

Actually, better would be to use REGEX()

Something like: (untested)

ExecIf($["${REGEX("domain[.]com" ${PJSIP_HEADER(read,From)})}" == "1"]?Set(UWIPDEST="555.555.555.555"):Set(UWIPDEST="666.666.666.666"))

2 Likes

You can try ask Gemini or ChatGPT. I find them quite handy for trying to figure out regex.

1 Like

@billsimon that did it with some minor modification (removing quotes around the IPs).

ExecIf($["${REGEX("domain[.]com" ${PJSIP_HEADER(read,From)})}" == "1"]?Set(UWIPDEST=555.555.555.555):Set(UWIPDEST=666.666.666.666))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.