Dial Command g option, but if either side hangs up


I have a setup where I want to mute audio on an external system when a call is made via a shell script. Then start it back up when it ends
Using the g option it works fine, only if the called party hangs up ( as expected per the documentation). But how can I make it continue if the calling party hangs up 1st?

here is my config:
exten => 3001,1,TrySystem(/etc/asterisk/Scripts/3001.sh Mute_Room);
exten => 3001,2,DIAL(SIP/1001,20,g);
exten => 3001,3,WAIT(1);
exten => 3001,4,TrySystem(/etc/asterisk/Scripts/3001.sh Unmute_Room);
exten => 3001,5,Goto (macro-hangupcall,s,3);

I tried using the G option, but it triggers when the call is answered screwing everything up.

Should I be using something other than DIAL to connect the call?

Thank you,


OK, so this solution is super old, so old I don’t think it’s in the WIKI at all.

In the ‘utils’ section of Asterisk is muted, it comes with a sample config and an app you run, you can specify that it mutes any time a specific channel goes active.

Thanks for the reply, but looking at the comments of the .c file it monitors the specified channels and mutes the local machine when active. I need to send a message via syslog or snmp trap to an external system to tell it to mute/unmute when a call starts/ends. This is why I was trying to call a script before/after. It just seems odd that there is an option to continue steps when the called hangs up, but not the caller.

Oh bummer, I missed that it’s an external system.

I think muted might still hold a solution, you could write a script that talks to the manager interface and watches for calls to your specific device.

As an alternate idea you could try using both a predial and hangup handler if your asterisk version is new enough.



1 Like

Just to close the Hangup handler covered what I needed no matter what side hangs up. 1001 is the extension in the room, dialing 3001 will mute the room before placing the call into it.

exten => 100,1,TrySystem(/etc/asterisk/Scripts/SignalCrestron.sh Unmute_Room ${ARG1})
exten => 100,2,Return()

exten => 3001,1,TrySystem(/etc/asterisk/Scripts/SignalCrestron.sh Mute_Room 1001);
exten => 3001,2,Set(CHANNEL(hangup_handler_push)=hdlr1,100,1(1001));
exten => 3001,3,DIAL(SIP/1001,20);


Great! I am glad you were able to solve your issue.