Tim Wolak wrote:
I have modified the code however its still not writting to the file.... Not sure what is going on, I have tried different ideas to get it to pint to the file but so far no go. Does anyone have any ideas? #!/usr/bin/perl -w use strict; use warnings; my $logfile = '/var/log/messages'; my $secv = '/var/log/secv'; my $hosts = '/etc/hosts.deny'; my $cody = '/etc/hosts.txt'; my @boxes; my $box; open(LOG, $logfile) || die "Cannot open logfile for reading: $!"; open(SEC, '>$secv') || die "Can't open file!: $!"; open(HOST, $hosts) || die "Can't open file!: $!"; open(DENY, '>>$cody') || die "Can't open file!: $!"; foreach (<HOST>) { push @boxes, $1 if /(\d+\.\d+\.\d+\.\d+)/; } close HOST or die $!; while (<LOG>){ next unless /Failed password for invalid/; print SEC "Invalied user logon attempt!:$_\n"; next unless /(\d+\.\d+\.\d+\.\d+)/; my $tim = $1; foreach $box (@boxes) { if ($box eq /$tim/){ next; } else { print DENY "$tim\n"; } } } close SEC or die $!; close DENY or die $!; close LOG or die $!;
I think you want: foreach my $box (@boxes) { if ($box eq $tim){ print DENY "$tim\n"; last; } } HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>