use strict; use Win32::ChangeNotify; use Win32::IPC; use File::Basename; use File::Glob; use DBI; use threads; my $path = 'c:\temp\buffer\event'; #$|=1; my @threads; ### Main program part my $notify = Win32::ChangeNotify->new( $path, 0, 'FILE_NAME' ); my %last;@last{ glob $path . '\*' } = (); CHECK_MAIN(); while( 1 ) { $notify->wait; $notify->reset; my @files = glob $path . '\*'; if(@files == scalar keys %last) { my %temp; @temp{ @files } = (); delete @temp{ keys %last }; foreach my $file (keys %temp){ my $currentFile = basename $file; if ($currentFile =~ /\.log$/){ push @threads, async \&READ_FILE($file); # READ_FILE("$file"); } } } undef %last; @last{ @files } = (); } $_->join for @threads; exit 0; sub CHECK_MAIN{ } sub READ_FILE{ my $file = shift; my $pattern; my $errMsg; open(F, "unix.txt")|| die "unix\.txt not found\nopen : $!"; while(){ chomp($_); $pattern .= $_."|"; } close(F); chop($pattern); my (@errlog, @normal) = (); chomp($file); $file =~ s/\\/\//g; sleep 1; open(TARGET, $file) || die "$file not found\nopen : $!"; while (){ if(/$pattern/ig){ next if(/root\-oracle/ig); chomp($_); my $temp = "$&\|".$_; push (@errlog, $temp); }else{ push (@normal, $_); } } close(TARGET) || warn "close : $!"; # print "@errlog"; #SEND_SMS(\@errlog) if(@errlog > 0); #ADD_DATA(\@errlog) if(@errlog > 0); } # END of READ_FILE