Re: Автодозвон
#!/usr/bin/perl
use DBI;
my $work = 1;
while($work = 1) {
$dirs_files = `find /var/spool/asterisk/outgoing/ -type f | wc -l`;
print "To chto vernuli ",$dirs_files,"\n";
if ($dirs_files < 5){
Tel_Zapr(5 - $dirs_files);
}
print "----------------\n";
sleep 2;
}
sub Tel_Zapr {
my $number_tel = shift;
print "number_tel ",$number_tel,"\n";
sleep 2;
my $dbh = DBI->connect ('DBI:mysql:database=spravka;host=localhost', 'root', '')
or die "Can't connect MySQL server\n";
$MyQueri = "select id,num from obzvon where priznak = 0 order by id limit $number_tel";
my $sth = $dbh->prepare($MyQueri);
if (!$sth) {
die "Error:" . $dbh->errstr . "\n";
}
if (!$sth->execute) {
die "Error:" . $sth->errstr . "\n";
}
while ( my ($id,$num) = $sth->fetchrow_array()) {
print $id," ",$num,"\n";
Zapis_DB("UPDATE obzvon SET priznak = 1 where id = '$id'");
Create_call_files($num,$id);
}
$sth->finish();
$dbh->disconnect();
}
sub Create_call_files {
my $num = shift;
my $id = shift;
$ret_call = system("echo 'Channel: SIP/10612#$num\@81\nCallerID: 80487791591\nMaxRetries: 1\nRetryTime: 60\n
WaitTime: 30\nContext: popuga\nExtension: s\nPriority: 1\nSet: MyCALL=$num' > /var/spool/asterisk/outgoing/$id_$num.call");
}
sub Zapis_DB {
my $dbh = DBI->connect ('DBI:mysql:database=spravka;host=localhost', 'root', '')
or die "Can't connect SQL server\n";
$dbh->do($_[0]);
$dbh->disconnect();
}
примерно так
|