Kebanyakan log kannel itu 'sakit' (log bearerbox) dan memang seharusnya kalo mau parse jangan yang bb-access.log tapi (mungkin) bb.log atau sb.log, so saya bikin skrip ini hanya buat iseng isengan lagi dengan Perl.
#!/usr/bin/perl
use strict;
use warnings;
use lib 'lib';
use Data::Dumper;
use POSIX qw(strftime);
#use Unix::PID 'xlogr.pid';
use File::Tail::App qw(tail_app);
my $stat;
tail_app({
'new' => ['/var/log/kannel/bb-access.log'],
'line_handler' => \&_wag_tail,
'lastrun_file' => 'x.lastrun',
});
sub _wag_tail {
my($line) = @_;
if($line =~ /(\d{4}-\d{2}-\d{2})\s
(\d{2}:\d{2}:\d{2})\s
(\w.*?\sSMS)\s
\[(\w.*?)\]\s
(.*)/gix)
{
_Handle($1,$2,$3,$4,$5);
}
system('clear');
print Dumper(\$stat);
}
sub _Handle {
my ( $date, $hour, $type, $smsc, $status ) = @_;
if($stat->{_date}{$date}{$type}{$smsc}){
$stat->{_date}{$date}{$type}{$smsc}++
} else {
$stat->{_date}{$date}{$type}{$smsc} = 1
};
}
Seharusnya pake curses dan teman teman ya ?
Saya cuman merasa malu dengan
system ('clear')
.. he he
No comments:
Post a Comment