Monitor Active Calls with conditions?

Asterisk 13.18.1
Centos 7

I currently use in linux commands to see active calls but I have to keep calling it manually

Basically it shows all details of all active calls but I filter out only channel name and the duration of the calls
but it there a way to keep active watch over it and if duration if over certain amount of time then execute a hangup request?

I tried watch command but if I do that I cant use awk command?
any help would be great

sudo asterisk -x 'core show channels concise' | awk -F! '{ if(NR>1) print $1 " ("strftime("%Y-%m-%d %H:%M:%S", $12)")" }'

The L option on Dial sets a time limit.

1 Like

it can be done, you need to monitor calls and grab the call duration and channel name and once you find the one who match the duration condition use SoftHangup() command to hangup the calls.
Linux AWK and grep

1 Like

if anyone else needs this here it is
i had to escape all variable starting with $ because of watch double quote
watch core show channels concise format


-t: get rid of watch header
-n 2: timer update every 2 seconds
awk -F!: split with delimiter !
NR: is number row 1 (dont show)
$12" is variable with duration in seconds
if(NR>1 && $12<120): dont show line 1 and duration is less than 120 sec hangup
strftime: print in readable format
system: call script hangup,sh and pass channel name with $1

I had to pass into script because I didnt know how to escape the double quote twice, if you can solve that for me awesome because i kept trying and I kept gettings erros so i decied to pass to external script
watch " system(" asterisk -rx ------>“hangup request $1”<----- ") "
arrow pointing at double quote that cause me errors

sudo watch -t -n 2 "asterisk -x 'core show channels concise' | awk -F! ' { if(NR>1 && \$12<120) {print \$1 strftime(\" %H:%M:%S\", \$12)}else if(NR>1) {system(\"/home/user/ \"\$1)} }'"
asterisk -rx "hangup request $1"


1 Like