dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
138
share rss forum feed

SCADAGeo

join:2012-11-08
N California
kudos:2
reply to dangmoo

Re: [Asterisk] hangup a channel from bash - odd behavior

said by dangmoo:

Although in both cases the $CHANNEL variable seems to hold a perfectly valid channel name - Asterisk refuses to hang it up and outputs "unknown channel".

I could see this occurring if ext124 called ext125... there would be too many arguments passed to "channel request hangup" (ext124 would be in two lines).

Does this work on your system?

#!/bin/bash
 
if [ $# != 1 ]
then
   echo "   Usage: $0 extension"
   exit
fi
echo;
 
CHANNEL=`asterisk -rx "core show channels concise" | cut -f1 -d'!' | grep $1`
 
for i in ${CHANNEL}
do
   echo -n "Request hangup on channel ${i} "
   read -p "(y/n)? " ans
   if [ ${ans} == "y" ]
   then
      echo "Requesting hangup on ${i}..."
      asterisk -rx "channel request hangup ${i}"
   fi
done
 
echo;
 

dangmoo

join:2012-02-09

1 edit

.


dangmoo

join:2012-02-09
reply to SCADAGeo

Thank you SCADAGeo but this is not working.
FYI I had to tweak the $CHANNEL var declaration in your code to make more sense, as follow:
CHANNEL=`asterisk -rx "core show channels concise" | grep $1 | cut -f1 -d'!'`
 
but anyway I'm still getting the same problem: although $CHANNEL holds the right value, Asterisk keeps refusing the hangup request

Here's how it looks like on bash shell:

root@codeplace:~# asterisk -rx "core show channels concise"
SIP/1001-00000022!default!124!7!Ring!Playback!holdmusic,noanswer!1001!!!3!17!(None)!1355355807.34
 
root@codeplace:~# ./hangup.sh 124
 
Request hangup on channel SIP/1001-00000022 (y/n)? y
Requesting hangup on SIP/1001-00000022...
SIP/1001-00000022 is not a known channel
 
Any other idea??

SCADAGeo

join:2012-11-08
N California
kudos:2

said by dangmoo:

SIP/1001-00000022 is not a known channel
 
Any other idea??

That's really strange. I'm running it under Centos 5.7, GNU bash version 3.2.25(1)-release (i686-redhat-linux-gnu).

Does this work from the command line:

asterisk -rx "channel request hangup SIP/1001-00000022"
 

If it does, I would try 'exec'

exec asterisk -rx "channel request hangup ${i}"
 

to see what happens.

BTW - there is a note in Asterisk 10.0.1 cli.c, that the 'concise' option is deprecated.

dangmoo

join:2012-02-09

when I hangup like this

asterisk -rx "channel request hangup SIP/1001-00000022"
 
it has always been working... but the whole issue is about the need to do it programatically, from a variable.

When I change your script to include the 'exec' , I'm still getting the same 'unknown channel' problem.

No luck with this yet...

I wonder what could be a different approach for my goal. All I need is hangup channel which is connected to specific extension. Is there another command whereby I can extract this data (full channel name + extension)??


Trev
IP Telephony Addict
Premium
join:2009-06-29
Victoria, BC
kudos:6

Check out AMI - Asterisk Manager Interface.

You won't get away with a one-liner, but you will get a significantly more reliable way of gathering call details and manipulating calls.
--
Wondering what I do? Find out at »www.digitalcon.ca
Get your Obihai ATA in Canada.


dangmoo

join:2012-02-09

said by Trev:

Check out AMI - Asterisk Manager Interface.

Thanks, but since I'm planning to eventually use such hangup request as a simple dialplan priority, using System() or Shell() , I wouldn't go that far for such a simple task.



Trev
IP Telephony Addict
Premium
join:2009-06-29
Victoria, BC
kudos:6
reply to Trev

In that case perhaps this would work for you:

- when a call to the extensions that may need hanging up come in, set a global variable with that extension number to the channel name
- create an extension that's sole purpose is to Hangup
- use the ChannelRedirect application to redirect that channel to the Hangup extension
--
Wondering what I do? Find out at »www.digitalcon.ca
Get your Obihai ATA in Canada.


SCADAGeo

join:2012-11-08
N California
kudos:2

said by Trev:

In that case perhaps this would work for you:

- when a call to the extensions that may need hanging up come in, set a global variable with that extension number to the channel name
- create an extension that's sole purpose is to Hangup
- use the ChannelRedirect application to redirect that channel to the Hangup extension

Nice way to work around the problem.

Debian 6 has a newer version of bash, so I wondered if it was an expansion quirk in the new version.

I downloaded v4.2.0, compiled, called it normally and with --posix.

Both methods worked... not sure where to go from here...

Just out of curiosity, are you running Debian 6.0.6?

What do the following show?

whereis asterisk

asterisk -rx "core show version"

grep ^`whoami` /etc/passwd

echo $SHELL

/bin/bash --version

dangmoo

join:2012-02-09

1 edit
reply to Trev

said by Trev:

In that case perhaps this would work for you:

- when a call to the extensions that may need hanging up come in, set a global variable with that extension number to the channel name
- create an extension that's sole purpose is to Hangup
- use the ChannelRedirect application to redirect that channel to the Hangup extension

Thank you Trev, based on your tip the problem has been solved. Bravo.

A priority was added to the target extension like this:
same => n,Set(GLOBAL(CHANTOKILL)=${CHANNEL})
 

and by adding this line to any other extension, call is hangup:
same => n,Set(result=${SHELL(asterisk -rx "channel request hangup ${CHANTOKILL}")})
same => n,NoOp(result is: ${result})
 

However, I'm still curious why the original code didn't work for me. This will remain an open question until someone solves this mystery

SCADAGeo

join:2012-11-08
N California
kudos:2

said by dangmoo:

said by Trev:

In that case perhaps this would work for you:

Thank you Trev, based on your tip the problem has been solved. Bravo.

Cool!

said by dangmoo:

It worked normally when using the command without variables. Problem occurred only when a variable was involved

I understood.

said by dangmoo:

However, I'm still curious why the original code didn't work for me. This will remain an open question until someone solves this mystery

I am curious, too, that's why I asked for the information.

I want to recreate your environment, but the full distro of Debian 6.0.6 contains 7 DVD's... it would be a waste of bandwidth and time to download a version that is different than the one you are using.

dangmoo

join:2012-02-09

1 edit

Sure SCADAGeo, sorry for delay.
I'm on a Debian Squeeze 32bit VPS, connected via SSH. Yes, it's the version 6.0.6 .
Hope the following info helps:

root@codeplace:~# cat /etc/debian_version
6.0.6
root@codeplace:~# whereis asterisk
asterisk: /usr/sbin/asterisk /etc/asterisk /usr/lib/asterisk /usr/include/asterisk /usr/include/asterisk.h /usr/share/man/man8/asterisk.8
root@codeplace:~# asterisk -rx "core show version"
Asterisk 1.8.3.3 built by root @ codeplace on a i686 running Linux on 2012-12-09 21:30:06 UTC
root@codeplace:~# grep ^`whoami` /etc/passwd
root:x:0:0:root:/root:/bin/bash
root@codeplace:~# echo $SHELL
/bin/bash
root@codeplace:~# /bin/bash --version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>