Sign in to follow this  
Followers 0
volptester

asterisk controlled by a bash script

4 posts in this topic

I'm building a tool to test some stuff for work using asterisk

I've already figured out how to write a dial plan for asterisk 1.4 that will go off-hook on the FXS port of my ATA and play one or two sound files and then hang-up. I've created a bash script to make that happen.

What I need to be able to do is to write a script that would let me one time go off-hook, play sound 1, hang-up; and another time; go off-hook, play sound 2, play sound 3, hang-up, etc.

Each time I've got to be able to go off-hook, play 1 to 99 samples according to how I evoke the script, and then hang-up, but without going in and editing /etc/asterisk/extensions.conf every single time I want to change the tests. I could make a dial plan section for "going off hook", "playing sample 1" but I need to be able to jump between them under control of something external to asterisk, and without hanging up between.

I'm a total n00b on asterisk, but I've learned enough to know I need to steer clear of any 1.2 howtos

I don't need any code samples but I'd like a nudge in the right direction. I've been thinking that one approach might be to use an add-on called `backticks`.

(Actually, I'm planning on creating a function that would open the serial port and start logging, play a sample, close the port, grep the logged lines for keywords, and log the results to a remote file, but I know how to do all that already)

TIA

0

Share this post


Link to post
Share on other sites

Well, with no answer, I thought I'd paste in what's working (sorta) for the moment:

[callbot]

;exten => s,1,Answer ; not needed for a FSX port!

exten => s,1,Wait(3) ; adjust delay as needed

exten => s,n(get),Set(next=${SHELL(/bin/cat /tmp/asterisk/next.txt | tr -d '\n')}) ;`tr` gets rid of trailing newline

exten => s,n,System(rm /tmp/asterisk/next.txt) ; wipe after reading the file

; remember to chmod and chown /tmp/asterisk/ and any files so this works

;PROBLEM! next command does not work, so no way to exit w/o just not creating the next command file

;exten => s,n,GotoIf("$next" = "STOP"?end) ; if S{NEXT} is "STOP" then we end the loop

exten => s,n,Background(${next}) ; otherwise, hopefully we have a command to play

exten => s,n,Wait(1) ; delay after playing the command

exten => s,n,Goto(get) ; loop back around and fetch next command

exten => s,n(end),Noop(end, just before h/u)

exten => t,1,Hangup

I'd like to figure out why I can't get the fourth commented-out line to work, and then I suppose figure out how to get the dial plan to wait if there's not a file to consume at the moment.

I'm at 1.6 not 1.4, so System() works and I don't need Backticks(). There's no need to jump around to a bunch of sections if I can have this loopy thing just take keep taking what I feed it via /tmp/asterisk/next.txt

I'm building a tool to test some stuff for work using asterisk

I've already figured out how to write a dial plan for asterisk 1.4 that will go off-hook on the FXS port of my ATA and play one or two sound files and then hang-up. I've created a bash script to make that happen.

What I need to be able to do is to write a script that would let me one time go off-hook, play sound 1, hang-up; and another time; go off-hook, play sound 2, play sound 3, hang-up, etc.

Each time I've got to be able to go off-hook, play 1 to 99 samples according to how I evoke the script, and then hang-up, but without going in and editing /etc/asterisk/extensions.conf every single time I want to change the tests. I could make a dial plan section for "going off hook", "playing sample 1" but I need to be able to jump between them under control of something external to asterisk, and without hanging up between.

I'm a total n00b on asterisk, but I've learned enough to know I need to steer clear of any 1.2 howtos

I don't need any code samples but I'd like a nudge in the right direction. I've been thinking that one approach might be to use an add-on called `backticks`.

(Actually, I'm planning on creating a function that would open the serial port and start logging, play a sample, close the port, grep the logged lines for keywords, and log the results to a remote file, but I know how to do all that already)

TIA

0

Share this post


Link to post
Share on other sites

Put a perl/other script in place of the wav file, and have that script direct-output one of x wav at startup ?

0

Share this post


Link to post
Share on other sites

Put a perl/other script in place of the wav file, and have that script direct-output one of x wav at startup ?

I'm doing this w/ a shell script.

What's working for me right now is to have my dial plan look at that temp file every once in a while and if it finds a name of a sound file, it plays it to the fxs port. I'll probably have it read from another temp file at some point and adjust the delay for speaking the next command.

My bash script then forks something that opens the serial port, logging it's PID so it can kill it x seconds later. I'm then grepping that log and writing to another log (which is to be read by a human)

I was trying to kludge together a 2-D array in bash, but ran across an emulation of a push/pop stack. The script opens a plain text file of commands and pushes them into the stack, last command first, it then pops off a command and writes to the above temp file, where asterisk reads from.

I'm really running up against the limits of a shell script on this project but I can't take the time off to restart the project into another language. I know bash best. I needed this script yesterday, and may have it usable by next week.

Thanks for your suggestion.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0