Running shell script from within the DialPlan

Hi all,
I have searched long and hard for an answer to the problem that I face and so far have not found it. Here is the situation: I have FreePBX 4.211.64-5 installed and running. 20 SIP phones run fine, incoming POTS line is fine on Digium card. I have it connected to my bell system (installation is in a school) so that we can do overhead paging. I have an extension setup for the paging. Here it is in brief:
exten => 8,1,Answer()
same => n,System(/etc/asterisk/

Inside of the script is this:

/usr/bin/amixer -q -c 0 sset ‘Audigy Analog/Digital Output Jack’ unmute

The soundcard never unmutes when run from inside the dialplan, however if I run it from the CLI like this:
it runs fine, soundcard is unmuted and I can call extension 8 and hear myself talk. I have tried several different things to get this to work. I can post log files if needed, but all that I see are messages like the following:
[2013-10-28 13:40:20] VERBOSE[3208][C-00000000] pbx.c: – Executing [[email protected]:2]System(“SIP/211-00000000”,"/etc/asterisk/") in new stack
I have more information about it posted here:

Thanks for any help! It is greatly appreciated!

It is almost certyainlyy permissions,

!sudo -uasterisk etc/asterisk/

is a fairer test as


will run the script as root.

Thank you for the suggestion! I changed the dialplan line to be:
same => n,System(!sudo -uasterisk /etc/asterisk/ and now I receive this error message:
app_system.c: Unable to execute ‘!sudo -uasterisk /etc/asterisk/’ in the log file. asterisk is the owner of the script. What other permissions would I be looking at?

You miss the point, the “!sudo . . .” is only from the asterisk CLI, it will then run the script with asterisk user permissions, and will tell you why it won’t run, probably “permission denied”.

I imagine that the audio device is what is not available to the asterisk user.

Ah, I DID miss that point - thank you for correcting me. However, it doesn’t make a difference. If I run:!/etc/asterisk/ - or - !sudo -uasterisk /etc/asterisk/
from the asterisk cli the result is the same: the sound card is unmuted. I can’t get any error returned from the dialplan when I run the script from there. I modified the dialplan to run the amixer command directly and I received a mail message to the root user telling me that asterisk was not a member of the sudoers group. I ran visudo and gave the asterisk user permission to run the amixer command: Low and Behold!! It Worked!! (well, half-way, I can unmute the card, but now it doesn’t mute on hangup - I’m guessing a dialplan error here). Thanks for the pointers!! I’ll post back when I have it complete. If you have suggestions on the dialplan layout I’ll take them as well! Here is the current dialplan for reference:

exten => 8,1,Answer()
same => n,TrySystem(sudo -uasterisk /usr/bin/amixer -c 0 sset ‘Audigy Analog/Digital Output Jack’ unmute)
same => n,Dial(console/dsp,gA(beep))
same => n,TrySystem(sudo -uasterisk /usr/bin/amixer -c 0 sset ‘Audigy Analog/Digital Output Jack’ mute)
same => n,Hangup()

If asterisk has access to amixer then you do not need the sudo bit.

You should probably examine the value of ${SYSTEMSTATUS} after calling the TrySystem application for “SUCCESS”

Okay, after a bit of testing I realize that I can’t do it all in one step (i.e. during the call to just the page extension). Here is what I have come up with. I think my logic is okay, but it fails at the ‘h’ extension. The goal being to a) call the page, b) record a message, c) hangup from handset/phone, d) unmute sound card, e) play a beep for attention, f) play recorded message, g) mute the sound card:
exten => 8,1,Answer()
same => n,Record(paging:gsm,3,30,k)
same => n,Hangup()
exten => h,1,TrySystem(sudo -uasterisk /usr/bin/amixer -c 0 sset ‘Audigy Analog/Digital Output Jack’ unmute)
exten => h,2,Dial(console/dsp,gA(beep))
exten => h,3,Playback(paging)
exten => h,4,TrySystem(sudo -uasterisk /usr/bin/amixer -c 0 sset ‘Audigy Analog/Digital Output Jack’ mute)

Here is the output from the “full” logfile:
Executing [[email protected]:1] Answer(“SIP/211-00000086”, “”) in new stack
[2013-10-31 14:55:48] VERBOSE[11708] chan_sip.c: == Extension Changed 211[ext-local] new state InUse for Notify User 204
[2013-10-31 14:55:48] VERBOSE[19221][C-00000080] pbx.c: – Executing [[email protected]:2] Record(“SIP/211-00000086”, “paging:gsm,3,30,k”) in new stack
[2013-10-31 14:55:48] VERBOSE[19221][C-00000080] file.c: – <SIP/211-00000086> Playing ‘beep.ulaw’ (language ‘en’)
[2013-10-31 14:55:52] VERBOSE[19221][C-00000080] pbx.c: – Executing [[email protected]:1] Hangup(“SIP/211-00000086”, “”) in new stack
[2013-10-31 14:55:52] VERBOSE[19221][C-00000080] pbx.c: == Spawn extension (from-internal, h, 1) exited non-zero on ‘SIP/211-00000086’
[2013-10-31 14:55:52] VERBOSE[11708] chan_sip.c: == Extension Changed 211[ext-local] new state Idle for Notify User 204
Any suggestions on getting the recorded message to playback, followed by a muted sound card? I know the recording exists - I can play it back on a test extension.
P.S. The idea to have the record/playback method came from here:

Logic looks good but you can’t playback (or any audio stuff) in the h context

branch to a muteunmute context before hangup maybe.

or explore DeadAGI if all the variables are no longer variables.

Okay - I’ll give those two options a try and get back with you on results. Thanks!