Useless
This commit is contained in:
parent
7a6d9c1d12
commit
6290ac22a1
2 changed files with 64 additions and 7 deletions
32
parselog.pl
Executable file
32
parselog.pl
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/perl
|
||||
# Parses a log and generates some useless statistics.
|
||||
# $Amigan: cidserv/parselog.pl,v 1.1 2004/12/23 23:46:01 dcp1990 Exp $
|
||||
# (C)2004 Dan Ponte. BSD.
|
||||
$logfile = $ARGV[0];
|
||||
%stat = ('me' => (phone => '123345', times => 1,),);
|
||||
%numstat = (123345 => \$stat{'me'});
|
||||
open(LF, $logfile);
|
||||
@cont = <LF>;
|
||||
close(LF);
|
||||
print "parselog.pl v1.\n";
|
||||
foreach(@cont) {
|
||||
if($_ =~ /^Phone Number: ([0-9]+)$/) {
|
||||
$stat{$lnam}{'phone'} = $1;
|
||||
$numstat{$1} = \$stat{$lnam};
|
||||
} elsif ($_ =~ /^Name: (.+)$/) {
|
||||
$stat{$1}{'times'}++;
|
||||
$tottimes++;
|
||||
$stat{$1}{'name'} = $1;
|
||||
$lnam = $1;
|
||||
}
|
||||
}
|
||||
while(($k, $v) = each(%stat)) {
|
||||
# print $k . "\n";
|
||||
while(($ok, $ov) = each(%{$v})) {
|
||||
if($ok eq 'times' and $ov > $lg) { $lg = $ov; $hn = ${$v}{'phone'}; }
|
||||
# print $ok . ' = ' . $ov . "\n";
|
||||
}
|
||||
}
|
||||
#print "be " . ${${$numstat{$hn}}}{'times'} . "\n";
|
||||
print ${${$numstat{$hn}}}{'name'} . " ($hn) called the most times, at $lg.\n";
|
||||
print "In total, people called here $tottimes times.\n";
|
|
@ -32,7 +32,7 @@ int ring = 0, nhosts = 0;
|
|||
char hosts[10][18];
|
||||
FILE* logfh;
|
||||
char* devi;
|
||||
static const char rcsid[] = "$Amigan: cidserv/src/cidserv.c,v 1.2 2004/12/23 23:13:05 dcp1990 Exp $";
|
||||
static const char rcsid[] = "$Amigan: cidserv/src/cidserv.c,v 1.3 2004/12/23 23:46:03 dcp1990 Exp $";
|
||||
int modemfd, sfd;
|
||||
struct tm *ct;
|
||||
time_t now;
|
||||
|
@ -65,9 +65,32 @@ void brring(void)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
static void trap_signal(int nused)
|
||||
static void trap_hup(int nused)
|
||||
{
|
||||
fprintf(stderr, "Caught signal %d, cleaning up...\n", nused);
|
||||
fprintf(stderr,
|
||||
"Caught signal %d\n", nused);
|
||||
fflush(logfh);
|
||||
parse_cid("80190108313232313135303508014F020A3430313437343737343063\n");
|
||||
return;
|
||||
}
|
||||
static void trap_usr1(int nused)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Caught signal %d\n", nused);
|
||||
parse_cid("802701083039303532303130070F574952454C4553532043414C4C2020020A30303332303532363239AF\n");
|
||||
return;
|
||||
}
|
||||
static void trap_usr2(int nused)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Caught signal %d\n", nused);
|
||||
parse_cid("802701083132323130383234070F5354414E444953482048454154494E020A343031333937333337325C\n");
|
||||
return;
|
||||
}
|
||||
static void trap_term(int nused)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Caught signal %d, cleaning up...\n", nused);
|
||||
fprintf(logfh, "%s Caught signal %d, cleaning up...\n",
|
||||
logtime(), nused);
|
||||
fflush(logfh);
|
||||
|
@ -171,9 +194,11 @@ int main(int argc, char* argv[])
|
|||
fflush(logfh);
|
||||
modemfd = open(dev, O_RDWR);
|
||||
lres = uu_lock((dev+(sizeof("/dev/")-1)));
|
||||
signal(SIGTERM, trap_signal);
|
||||
signal(SIGHUP, trap_signal);
|
||||
signal(SIGINT, trap_signal);
|
||||
signal(SIGTERM, trap_term);
|
||||
signal(SIGHUP, trap_hup);
|
||||
signal(SIGUSR1, trap_usr1);
|
||||
signal(SIGUSR2, trap_usr2);
|
||||
signal(SIGINT, trap_term);
|
||||
if(lres != 0) {
|
||||
fprintf(stderr, "%s\n", uu_lockerr(lres));
|
||||
exit(-1);
|
||||
|
@ -247,7 +272,7 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
switch(getc(stdin)) {
|
||||
case 'q':
|
||||
trap_signal(SIGTERM);
|
||||
trap_term(SIGTERM);
|
||||
break;
|
||||
case 's':
|
||||
parse_cid("802701083039303532303130070F574952454C4553532043414C4C2020020A30303332303532363239AF\n");
|
||||
|
|
Loading…
Reference in a new issue