Подскажите почему не отрабатывает скрипт? Ситуация такая: есть БД Постгриса, в которую парсятся логи Сквида по алгоритму - подключаемся к БД-Сбрасываем индексы-Вставляем данные в таблицу учитывающую ВСЕ запросы пользователей - Очищаем таблицу где собраны суммарные данные за день по юзерам - суммируем записи из подробной таблицы и вписываем эти данные в общую таблицу - дальше обслуживание БД (создание индексов, дефрагментация и пр.) Индексы то он сбрасывает и данные в подробную таблицу вписываются, а вот дальше никак. И логов то нет, чтобы посмотреть что не так (правда когда скрипт вручную запускаю с консоли видно как он выдает ошибки типа "use of uninitialized value in concatenation (.)"
Вот текст скрипта:#!/usr/bin/perl -w
use DBI;
use Time::localtime;
use MIME::Lite;
open (f2,">>/var/log/inetsys/inetcheck.log");
$dbh = DBI->connect('DBI:Pg:dbname=billingdb;host=192.168.0.3','billing','passwdbill')
or mail("Billing-system[Squid]","Could't not connect to the data base or data base does not exists");
$count = 0;
$count_inform = 0;
$tm_start = localtime;
$start_prog = sprintf ("d-d-d d:d:d\n",
$tm_start->year+1900,
$tm_start->mon+1,
$tm_start->mday,
$tm_start->hour,
$tm_start->min,
$tm_start->sec);
open (f1,"/home/squid/access.log")
or mail("Billing-system[Squid]","Counld't open squid file or file does not exists");
$dbh->do("DROP INDEX control_dat") or mail("Billing-system[Squid]","Counld't drop index control_dat on sum_traf");
$dbh->do("DROP INDEX sum_traf_usr") or mail("Billing-system[Squid]","Counld't drop index sum_traf_usr on sum_traf");
$dbh->do("DROP INDEX control_begin_time") or mail("Billing-system[Squid]","Counld't drop index begin_time on control");
while (<f1>)
{
(@args) = split(/\s+/,$_);
($_, $url) = split (/:\/\//,$args[6]);
@host = split(/\/+/,$url); #БШДХПЮЕЛ ХГ спкЮ ОПНРНЙНК Х ЯНУПЮМЪЕЛ спк
($res_cache,$squidus) = split(/\//,$args[3]); # БШДХПЮЕЛ ЯРЮРСР ОНОЮДЮМХЪ Б ЙЕЬ
$start = starttime($args[0]);
if (($res_cache eq 'TCP_HIT') ||
($res_cache eq 'UDP_HIT') ||
($res_cache eq 'TCP_HIT_MEM') ||
($res_cache eq 'TCP_IMS_HIT') ||
($res_cache eq 'TCP_NEGATIVE_HIT') ||
# ($res_cache eq 'TCP_REFRESH_HIT') ||
($res_cache eq 'TCP_REF_FAIL_HIT') ||
($res_cache eq 'UDP_HIT_OBJ') ||
($res_cache eq 'TCP_DENIED'))
{
}
else
{
if ($args[7] =~ /\\/){($dom,$usr) = split (/\\/,$args[7]);}
else {$usr = $args[7];}
# ($dom,$usr) = split (/\\/,$args[7]);
$dbh->do("INSERT INTO control VALUES ('$args[2]',$args[1],$args[4],'$start','$host[0]','$usr')")
or mail("Billing-system[Squid]","Counld't insert records to the data base in table 'inform' with tables 'idkey'");
$count_inform++;
}
$count++;
}
$squidus_done = 0;
sub starttime
{
$tm = localtime ($args[0]);
@tim = ($tm->year+1900, $tm->mon+1, $tm->mday,$tm->hour, $tm->min, $tm->sec);
$str = "$tim[0]-$tim[1]-$tim[2] $tim[3]:$tim[4]:$tim[5]";
return $str;
}
sub mail
{
$msg = MIME::Lite->new(
From =>'squid@ourcompany.ru',
To =>'root@ourcompany.ru',
Subject =>$_[0],
Type =>'TEXT',
Data =>"Billing report[Squid]"
);
$msg->attach(Type => 'text/html',
Data => qq{
$_[1]
}
);
MIME::Lite->send('smtp', "192.168.0.1", Timeout=>60);
$msg->send();
$squidus_done = 1;
}
$tm_stop = localtime;
$stop_prog = sprintf ("d-d-d d:d:d\n",
$tm_stop->year+1900,
$tm_stop->mon+1,
$tm_stop->mday,
$tm_stop->hour,
$tm_stop->min,
$tm_stop->sec);
$dbh->do("TRUNCATE TABLE sum_traf");
$dbh->do("insert into sum_traf select ipaddr,sum(query_time) as sum_time,sum(byte) as sum_byte,begin_time as dat, usr from control where begin_time >= '2007-01-01' group by ipaddr,dat,usr");
$tm_stop = localtime;
$create_table = sprintf ("d-d-d d:d:d\n",
$tm_stop->year+1900,
$tm_stop->mon+1,
$tm_stop->mday,
$tm_stop->hour,
$tm_stop->min,
$tm_stop->sec);
$dbh->do("CREATE INDEX control_dat ON sum_traf USING btree (dat)") or mail("Billing-system[Squid]","Counld't create control_dat index on sum_traf");
$dbh->do("CREATE INDEX sum_traf_usr ON sum_traf USING btree (dat)") or mail("Billing-system[Squid]","Counld't create sum_traf_usr index on sum_traf");
$dbh->do("CREATE INDEX control_begin_time ON control USING btree (begin_time date_ops)") or mail("Billing-system[Squid]","Counld't control_begin_time create index on control");
$tm_stop = localtime;
$create_index = sprintf ("d-d-d d:d:d\n",
$tm_stop->year+1900,
$tm_stop->mon+1,
$tm_stop->mday,
$tm_stop->hour,
$tm_stop->min,
$tm_stop->sec);
$dbh->do("VACUUM sum_traf");
$dbh->do("VACUUM control");
$tm_stop = localtime;
$create_vacuum = sprintf ("d-d-d d:d:d\n",
$tm_stop->year+1900,
$tm_stop->mon+1,
$tm_stop->mday,
$tm_stop->hour,
$tm_stop->min,
$tm_stop->sec);
$dbh->do("CLUSTER control_begin_time ON control");
$tm_stop = localtime;
$create_cluster = sprintf ("d-d-d d:d:d\n",
$tm_stop->year+1900,
$tm_stop->mon+1,
$tm_stop->mday,
$tm_stop->hour,
$tm_stop->min,
$tm_stop->sec);
$dbh->do("VACUUM ANALYZE sum_traf");
$dbh->do("VACUUM ANALYZE control");
$tm_stop = localtime;
$create_vacuum_analyze = sprintf ("d-d-d d:d:d\n",
$tm_stop->year+1900,
$tm_stop->mon+1,
$tm_stop->mday,
$tm_stop->hour,
$tm_stop->min,
$tm_stop->sec);
if (!$squidus_done)
{
mail("Billing-system[Squid]",
"Billing report start at $start_prog and stop at $stop_prog.<br>
Count all records are - $count.<br>
Count all inserted records in 'control' are - $count_inform.<br>
Create temp table at $create_table.<br>
Create index at $create_index. <br>
Create vacuum at $create_vacuum. <br>
Create cluster at $create_cluster. <br>
Create vacuum analyze at $create_vacuum_analyze. <br>
All right! Enjoy of new billing!");
unlink("/home/squid/access.log");
}