#!/bin/bash
set +o posix
shopt -s extglob
set -o pipefail
source /etc/profile

random-string()
{
    cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
}
file=$(random-string)
echo -e "$file"


Prefix=1
mdir=/var/spool/asterisk/outgoing
delay=1

Peer=8.19.245.233
K=300 #number of channels
y=0
while [ $y -lt $K ]
do
y=$[$y+1]
ani=0000000000
TO=99999
i=9545551212 # any 10 digit number
file=$(random-string)

printf -v x "Channel: SIP/%s%s@%s
CallerID: \"%s\" <%s>
WaitTime: 45
MaxRetries: 0
RetryTime: 10
Application: Echo
Data:
Setvar:TIMEOUT(absolute)=%s
Archive: no" $Prefix $i $Peer $ani $ani $TO 
f=/tmp/$file.call
echo -e "$f $x"
rm  $f -f
echo -e "$x" > $f
printf -v delay "%0.3f" $(bc <<< "$delay + 0.002")
touch -d "+ $delay seconds" $f
mv $f $mdir

done



