#!/usr/bin/perl use strict; use warnings; use POSIX 'strftime'; #my $filename = 'IGXLEventLog.3.17.2015.20.25.12.625.log'; my $directory = "/opt/lampp/htdocs/otpms/Data"; opendir (my $dir, $directory) or die "Could not open directory '$directory': $!"; my @list_files; our $output; my %details; for my $filename (@list_files) { open(my $fn, '<', $filename) or die "Could not open file '$filename': $!"; while(my $row = <$fn>) { chomp $row; if ($row =~ /Computer Name:\s*(\S+)/i ) # match computer name with white space then non white space { $details{tester_name} = $1; } elsif ($row =~ /Operating System:\s*(.*\S)/i ) # match operating system with white space then any word { $details{op_sys} = $1; } elsif ($row =~ /IG-XL Version:\s*([^;]*)/i ) # match ig-xl version with white space then semi colon { $details{igxl_vn} = $1; } elsif ($row =~ /^([\d.]+)\s+(\S+)(?=\s)/ ) #match slot with white space and then non white space { push @{$details{slot}}, $1; push @{$details{board_name}}, $2; } } close ($fn); my $timestamp = strftime '%Y-%m-%d.%H:%M:%S', localtime; $output = $timestamp .'.sql'; open(my $fh, '>', $output) or die "Could not create file '@output': $!"; my $log_time_stamp = (stat($filename))[9]; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($log_time_stamp); my $nice_timestamp = sprintf ( "%04d-%02d-%02d %02d:%02d:%02d", $year+1900,$mon+1,$mday,$hour,$min,$sec); print $nice_timestamp; for (my $i = 0; $i < @{$details{slot}}; $i++) { print {$fh} "INSERT INTO TesterDeviceMatrix.TBL_TESTER_INFO" ."(tester_name, operating_system, version, board_name, config , date_modified, log_created) " ."VALUES ('$details{tester_name}', '$details{op_sys}', '$details{board_name}[$i]', " ."'$details{igxl_vn}', '$details{slot}[$i]', '$timestamp', '$nice_timestamp');\n"; } close($fh); }