use strict; use warnings; use File::Basename; use Data::Dumper; my ($ServerName)=@ARGV; #ARGV = /var/log/server1.mydomain.com.backup-software.log my %MyItems; my $mon; my $day; my $year; foreach my $ServerName(@ARGV){ while (my $line = <>){ chomp $line; print "Line: $line\n" if debug; sub spGetCurrentDateTime; ($mon, $day, $year) = spGetCurrentDateTime; ($mon, $day, $year) = split(" ", $mon); if ($line =~ m/(.* $mon $day) \d{2}:\d{2}:\d{2} $year: ([^:]+):backup:/){ my $ServerName = basename $ARGV, '.mydomain.com.backup-software.log'; my $BckupDate="$1 $year"; my $BckupSet =$2; $MyItems{$ServerName}{$BckupSet}->{'1-Server'} = $ServerName; $MyItems{$ServerName}{$BckupSet}->{'2-Logdate'} = $BckupDate; $MyItems{$ServerName}{$BckupSet}->{'3-BackupSet'} = $BckupSet; if ($line =~ m/.* \w+ \d{2} (\d{2}:\d{2}:\d{2}) \d{4}: ([^:]+):backup:.*(START OF BACKUP)/){ my $BckupKey=$2; my $BckupVal=$1; $MyItems{$ServerName}{$BckupSet}->{'4-StartTime'} = $BckupVal; } if ($line =~ m/(backup-time)[:=](.+)/){ my $BckupKey="5-Duration"; my $BckupVal=$2; $MyItems{$ServerName}{$BckupSet}->{$BckupKey} = $BckupVal; } if ($line =~ m/(backup-size)[:=](.+)/){ my $BckupKey="6-Size"; #my $BckupKey=$1; my $BckupVal=$2; $MyItems{$ServerName}{$BckupSet}->{$BckupKey} = $BckupVal; } if ($line =~ m/(Backup succeeded)/){ my $BckupKey="7-Status"; my $BckupVal="Succeeded"; $MyItems{$ServerName}{$BckupSet}->{$BckupKey} = $BckupVal; } if ($line =~ m/(ERROR)[:=](.+)/){ my $BckupKey="8-Status"; my $BckupVal="Unsuccessful"; $MyItems{$ServerName}{$BckupSet}->{$BckupKey} = $BckupVal; } } } sub spGetCurrentDateTime{ my ($sec, $min, $hour, $mday, $mon, $year) = localtime(); my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); my $currentDateTime = sprintf "%s %02d %4d", $abbr[$mon], $mday, $year+1900; #Returns => 'Jul 26 2010' return $currentDateTime; } #print Dumper(\%MyItems); for my $ServerName(keys%MyItems){ for my $BckupSet(keys%{$MyItems{$ServerName}}){ for(sort keys%{$MyItems{$ServerName}{$BckupSet}}){ print$_,'=',$MyItems{$ServerName}{$BckupSet}{$_},';'; } print"\n"; } } }