Dynamic Route Doesn't Match

I have a dynamic route that checks if a DID is in the asterisk Phonebook.

${SHELL(if asterisk -x "database get cidname ${FROM_DID}"|grep -q not\; then echo NOMATCH \; else asterisk -x "database get cidname ${FROM_DID}"|cut -d ":" -f2|cut -d " " -f2\; fi)}

This works, I can see in the log the dynroute variable is correctly setting to NOMATCH.

210810	[2024-03-11 17:06:13] VERBOSE[26534][C-0000214d] pbx.c: Executing [s@dynroute-22:2] Set("PJSIP/AvayaSBCE-000031db", "dynroute=NOMATCH	
210811	") in new stack

The Problem:
Even though there is an entry for NOMATCH, it does not go that route, and instead goes the default route. Why is this? Is it a formatting mismatch? I notice on the log the " is split onto a second line (weird). Any ideas on how to fix @lgaetz or anyone?

try echo -n

1 Like

Clutch @dicko yet again!, that did it. Essentially the echo was returning a two line result, which is why the log was showing the result in two lines. -n suppresses the newline and keeps it all together.

Spoke too soon @dicko. It now works for the first half (the NOMATCH), but is not working for the matching half.

${SHELL(if asterisk -x "database get cidname ${FROM_DID}"|grep -q not\; then echo -n "NOMATCH"\; else asterisk -x "database get cidname ${FROM_DID}"|cut -d ":" -f2|cut -d " " -f2\; fi)}

The issue is the matching number is dropping a new line too. See below:

248805	[2024-03-11 18:26:04] VERBOSE[26872][C-0000217e] pbx_builtins.c: Goto (from-internal,5555555555	
248806	,1)

Any idea on what I need to modify in this line to stop a line break?
else asterisk -x "database get cidname ${FROM_DID}"|cut -d ":" -f2|cut -d " " -f2

Thanks!

pipe it through tr -d '\n'

1 Like

If you’re looking for an asterisk expression that will return the asterisk phonebook name if present for the number, or otherwise return the text “NOMATCH”, then you’ve made the task harder than it needs to be:

${IF($[${DB_EXISTS(cidname/${FROM_DID})}]?${DB(cidname/${FROM_DID})}:NOMATCH)}

Not precisely sure what you’re doing here, I would have assumed you want ${CALLERID(number)} not ${FROM_DID}`

1 Like

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