Perl Notes/spamtrainreport.pl
From Federal Burro of Information
Jump to navigationJump to search
#!/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; } } }