Conference bridge problem

Hello,

I am trying to set conference system that will allow to bridge pstn and voip conferences together,

So far I did this

created meetme conference room
conf => 500|1234

I created test extension 555, which does this:

exten => 555,1,MeetMeCount(500|count)
exten => 555,2,Gotoif,$[${count} = 0]?7
exten => 555,3,Gotoif,$[${count} = 1]?9
exten => 555,4,Meetme,500|cxAMs
exten => 555,5,Playback,goodbye
exten => 555,6,Hangup
exten => 555,7,Goto(from-internal-custom,556,1)
exten => 555,8,hangup
exten => 555,9,System(/usr/sbin/asterisk -rx “meetme kick 500 2”)
exten => 555,10,Goto(from-internal-custom,556,1)

1st check how many people are in meetme conference 500
if more than 1 skip to 9 if zero go to 7

this is done because if zap channel is still up (from previous conference) and in the conference it will block new

conference connection to pstn.
so my way is to check if there is more than 1 user in the conference, if yes it would mean
that zap channel is still up (this is my main problem , so thats why I do that)

if it is up I will go to extension 9 and I will kill it before I proceed
later I will run this:

exten => 555,10,Goto(from-internal-custom,556,1)
which initiates zap call using this file:

[root@asterisk1 asterisk]# cat 1-test
Channel: ZAP/4/91(number deleted)
Callerid: 1
MaxRetries: 1
RetryTime: 60
WaitTime: 30
Context: from-internal-custom
Extension: 561
Priority: 1

above would call pstn number and put the call into extension 561

extension 561 would later dial dtmf codes to connect to the conference with password:

exten => 561,1,wait,10
exten => 561,2,senddtmf(2)
exten => 561,3,senddtmf(7)
exten => 561,4,senddtmf(2)
exten => 561,5,senddtmf(5)
exten => 561,6,senddtmf(7)
exten => 561,7,senddtmf(3)
exten => 561,8,senddtmf(6)
exten => 561,9,senddtmf(#)
exten => 561,10,Meetme,500|qAx|1234
exten => 561,11,Hangup

at 561,10 it would go back to conference

at this time user is connected to 555 conference which is bridged with pstn conference

When new user connects he goes to extension
exten => 555,7,Goto(from-internal-custom,556,1)

which does:
exten => 556,1,System(/bin/cp /etc/asterisk/1-test /var/spool/asterisk/outgoing/)
exten => 556,2,goto(from-internal-custom,555,4)

because there are more than 2 users in the 500 conference (1st user and pstn user) more uses can connect to join the

bridge.

Problem!!!

When all users disconnect, the zap channel is still up.

it will be killed next time the new user connects to the conference.
During the silent time the zap channel will not be available.

So, I created temporary solution
i wrote this script:

[root@asterisk1 asterisk]# cat script
a=0
/usr/sbin/asterisk -rx "meetme list 500 " | grep Sip

if [ $? != 0 ];then
a=2
else
a=1
fi

/usr/sbin/asterisk -rx "meetme list 500 " | grep IAX

if [ $? != 0 ];then
a=2
else
a=1
fi

/usr/sbin/asterisk -rx "meetme list 500 " | grep Zap

if [ $? = 0 ];then
if [ $a = 2 ];then
/usr/sbin/asterisk -rx “meetme kick 500 2”
/usr/sbin/asterisk -rx “meetme kick 500 1”
/usr/sbin/asterisk -rx "meetme kick 500 3"
fi
fi

The script checks if zap channel is up, although the IAX or SIP are down.
If it is up it will kill the zap channel.

Problem is that running that script using cron starts a lot of rastersik processes and
asterisk stop working,

Any ideas how my problem could be solved?

Thx

Bart