#! /usr/bin/perl use POSIX; # directory server access log entries # Terry.Gardner@Sun.COM # 23 Mar 2004 sub getMonth { $mString = $_[0]; my $mon = 0; if ( $mString eq "Jan" ) { $mon = 0; } elsif( $mString eq "Feb" ) { $mon = 1; } elsif( $mString eq "Mar" ) { $mon = 2; } elsif( $mString eq "Apr" ) { $mon = 3; } elsif( $mString eq "May" ) { $mon = 4; } elsif( $mString eq "Jun" ) { $mon = 5; } elsif( $mString eq "Jul" ) { $mon = 6; } elsif( $mString eq "Aug" ) { $mon = 7; } elsif( $mString eq "Sep" ) { $mon = 8; } elsif( $mString eq "Oct" ) { $mon = 9; } elsif( $mString eq "Nov" ) { $mon = 10; } elsif( $mString eq "Dec" ) { $mon = 11; } return $mon; } $totalfiles = $#ARGV; print "FILE LINES SECONDS TOTAL SRCH DEL MOD ADD MODRDN BIND UNBIND EXT CONNECTIONS\n"; for( $file = 0; $file <= $totalfiles; $file++ ) { $lines = 0; $srchs = 0; $deletes = 0; $mods = 0; $adds = 0; $modrdns = 0; $binds = 0; $unbinds = 0; $total = 0; $results = 0; $ext = 0; $connections = 0; open( ACCESS,"$ARGV[$file]" ) || die "Cannot open $ARGV[$file]: $!"; while( ) { s/[\[\]]//g; ( $date_time,$junk ) = split(" ",$_,2); ( $date,$hour,$minute,$second ) = split(":",$date_time,4); if( $lines == 0 ) { ( $mday,$month,$year ) = split("/",$date,3); $year -= 1900; $start_time = mktime( $second,$minute,$hour,$mday,getMonth($month ),$year,0,0,0); } $lines++; if( m/ SRCH/ ) { $total++; $srchs++; } elsif( m/ BIND/ ) { $total++; $binds++; } elsif( m/ UNBIND/ ) { $total++; $unbinds++; } elsif( m/ DEL/ ) { $total++; $deletes++; } elsif( m/ MOD/ ) { $total++; $mods++; } elsif( m/ ADD/ ) { $total++; $adds++; } elsif( m/ MODRDN/ ) { $total++; $modrdns++; } elsif( m/ EXT/ ) { $total++; $ext++; } elsif( m/ RESULT/ ) { $results++; } elsif( m/ connection/ ) { $connections++; } } close( ACCESS ); ( $mday,$month,$year ) = split("/",$date,3); $year -= 1900; $end_time = mktime( $second,$minute,$hour,$mday,getMonth($month ),$year,0,0,0); if( $end_time > $start_time ) { $diff_time = $end_time - $start_time; } else { $diff_time = $start_time - $end_time; } if( $diff_time != 0 ) { $srchs_ps = $srchs/$diff_time; $deletes_ps = $deletes/$diff_time; $mods_ps = $mods/$diff_time; $adds_ps = $adds/$diff_time; $modrdns_ps = $modrdns/$diff_time; $binds_ps = $binds/$diff_time; $unbinds_ps = $unbinds/$diff_time; $ext_ps = $ext/$diff_time; $conns_ps = $connections/$diff_time; printf "$ARGV[$file] $lines $diff_time %d %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f\n", $total, $srchs_ps, $deletes_ps, $mods_ps, $adds_ps, $modrdns_ps, $binds_ps, $unbinds_ps, $ext_ps,$conns_ps; } }