Perl Notes/spamtrainreport.pl: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
(Created page with "<pre> #!/usr/bin/perl -w use strict; use DateTime; use DateTime::Format::Duration; my $foundtrainstart = 0; my $trainstart; my $trainend; my $datetimedurationformat = DateTime...") |
No edit summary |
||
Line 10: | Line 10: | ||
my $trainstart; | my $trainstart; | ||
my $trainend; | my $trainend; | ||
my $foundextractstart = 0; | |||
my $extractstart; | |||
my $extractend; | |||
my $datetimedurationformat = DateTime::Format::Duration->new( pattern => '%s' ); | my $datetimedurationformat = DateTime::Format::Duration->new( pattern => '%s' ); | ||
while (<>) { | while (<>) { | ||
if ( /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)\sStarting spamassassin training.$/ ) { | |||
$trainstart = DateTime->new( year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6 ); | |||
$foundtrainstart = 1; | |||
} | } | ||
if ( /Finished spamassassin training./) { | if ( /Finished spamassassin training./) { | ||
Line 30: | Line 31: | ||
} | } | ||
} | } | ||
if ( /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)\sStarting spam\/ham extraction from system accounts.$/ ) { | |||
$extractstart = DateTime->new( year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6 ); | |||
$foundextractstart = 1; | |||
} | |||
if ( /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)\sFinished extracting spam\/ham from system accounts./) { | |||
if ( $foundextractstart eq 1) { | |||
$extractend = DateTime->new( year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6 ); | |||
my $elapsed = $extractend-$extractstart; | |||
print "extract ".$extractstart." : ".$datetimedurationformat->format_duration($elapsed)."\n"; | |||
$foundextractstart = 0; | |||
} | |||
} | |||
} | } | ||
</pre> | </pre> |
Latest revision as of 04:07, 30 January 2012
#!/usr/bin/perl -w use strict; use DateTime; use DateTime::Format::Duration; my $foundtrainstart = 0; my $trainstart; my $trainend; my $foundextractstart = 0; my $extractstart; my $extractend; my $datetimedurationformat = DateTime::Format::Duration->new( pattern => '%s' ); while (<>) { if ( /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)\sStarting spamassassin training.$/ ) { $trainstart = DateTime->new( year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6 ); $foundtrainstart = 1; } if ( /Finished spamassassin training./) { if ( /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)\sFinished spamassassin training./) { if ( $foundtrainstart eq 1) { $trainend = DateTime->new( year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6 ); my $elapsed = $trainend-$trainstart; print "train ".$trainstart." : ".$datetimedurationformat->format_duration($elapsed)."\n"; $foundtrainstart = 0; } } } if ( /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)\sStarting spam\/ham extraction from system accounts.$/ ) { $extractstart = DateTime->new( year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6 ); $foundextractstart = 1; } if ( /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)\sFinished extracting spam\/ham from system accounts./) { if ( $foundextractstart eq 1) { $extractend = DateTime->new( year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6 ); my $elapsed = $extractend-$extractstart; print "extract ".$extractstart." : ".$datetimedurationformat->format_duration($elapsed)."\n"; $foundextractstart = 0; } } }