4

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'
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
sinaps1
  • 53
  • 6

2 Answers2

2

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
taliezin
  • 9,085
  • 1
  • 34
  • 38
0

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!

Alexey Vesnin
  • 180
  • 1
  • 8
  • 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. – sinaps1 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 01 '15 at 20:08