0

I'm trying to make a call using a call file on asterisk where it plays a file and hangs up after a given time whether the sound file has finished or not.

I have it working with this bash script as the AGI script:

#!/bin/bash

Duration="30"
file="sound.mp3"

while read VAR && [ -n ${VAR} ] ; do : ; done
echo "ANSWER"
read RESPONSE

echo 'SET AUTOHANGUP $Duration'

echo 'EXEC PLAYBACK "'$file'" ""'
read RESPONSE

exit 0

The problem is that the asterisk cdr logs show the call to last 30 seconds whether the the person on the other end has hung up or not...

Can anyone help?

Prince John Wesley
  • 62,492
  • 12
  • 87
  • 94
Tomcomm
  • 233
  • 2
  • 6
  • 16
  • 1
    can you show one cdr record as an example? have you tried setting it to different values than 30 (just to see if it will always set that number)? – marcelog Jun 20 '12 at 16:38

2 Answers2

0

OK this is embarrassing...

I cleaned up my code so that I could paste it on here and when I try again it seems to work how I want. Still don't know what then problem was but this code seems to work

#!/bin/bash

 Duration="20"
 file="soundfile"

while read VAR && [ -n ${VAR} ] ; do : ; done
echo "ANSWER"
read RESPONSE

echo 'SET AUTOHANGUP '$Duration''

echo 'EXEC PLAYBACK "'$file'" ""'
read RESPONSE

exit 0
Tomcomm
  • 233
  • 2
  • 6
  • 16
0

You can use the signal facility. For example:

#!/bin/bash
times_up(){ echo "time is up, pens down."; exit 0; }
trap 'times_up' ALRM
(sleep 10;kill -0 $$ && kill -ALRM $$)&

s=0
while (true) do
    sleep 1
    echo "$s: do my stuff"
    let s=$s+1
done
pizza
  • 7,296
  • 1
  • 25
  • 22