I am trying to create a script for Asterisk. We use a lot of channspy. Sometimes the channspy stays opened and didn't hangup even if the softphone is hangup (I don't understand why). So I thought of creating a script to take the number of channels opened started with the SIP/[extension]-channel and this grep export it to a TXT file this file will have 3 columns and extract just the first column with

awk ' {print $1} '

but here is where I stuck because each row has 1 channel and if I want to hangup this channel I have to do

asterisk -rx 'soft hangup SIP/[exntesion]-channel'

Can someone help me with this to get each row as a variable and loop the script till the last row. so the command will be something like

asterisk -rx 'soft hangup $variable'

Also you can use system with awk:

awk ' command = "asterisk -rx '\''soft hangup " $1 "'\''" { system(command); }' channels_file

just for testing:

awk ' command = "asterisk -rx '\''soft hangup " $1 "'\''" { print command; }' channels_file

cat 3-column-file-of-yours.txt | awk '{ sprintf "asterisk -rx \'soft hangup SIP/%s-channel\'\n",$1; }' | /bin/bash

Play with number of slashes near \' if you'll have trouble with the string and feel free to ask questions!

  • Seems like the command is not terminated it gors to another line that starts with > and then empty can't understand the os is cent os. – Argur Kasemi Mar 31 '15 at 11:09
  • can you please attach an example file and the command output you need to hangup - I'll debug it and post here – Alexey Vesnin Apr 1 '15 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.