Call a script on incoming external calls, then continue with default dial plan


I’ve switched from a pure Asterisk installation to a FreePBX based on. In my old environment I called a shell script on incoming external calls to trigger an external process. I’ve written all in the extensions.conf and everything was fine.

Now I want to move the line to call the shell script into the extensions_custom.conf. What I’ve tried:

exten => _X!,1,System(/bin/ “${CALLERID}” “${EXTEN}” "SIP/${ACCOUNTCODE})
exten => _X!,n,Goto(from-trunk,${EXTEN},1)

What I believe this should to: Call the script and then continue with the default dial plan.

But as soon as I include the .conf file in the Extensions.conf incoming and outcoming calls stop working. The error I get is following on an incoming call:

chan_sip.c:25732 handle_request_invite: Call from ‘621’ ( to extension ‘30154xxx’ rejected because extension not found in context ‘from-trunk’.

621 is the first sip account on my isdn gateway and 30154xxx the number I’m calling on an external device.

I’ve tried to base my code on the following example, taken for
exten => _X!,1,Set(CALLERID(num)=0${CALLERID(num)})
exten => _X!,n,Goto(from-trunk,${EXTEN},1)

It also makes no difference what context is used on my incoming settings for the trunks. The error stays the same.

Is there any best practices or advice? I simply want to call a script on incoming external calls. Thanks for any help!