perl 语法的新手,尝试设置一个计数器来计算日志文件中出现密码失败的次数,然后将总数打印到控制台。我在屏幕上打印了很多数字,而不是最后一个总数。任何想法或方向都会有所帮助。
#!/usr/bin/perl
$count = 0;
open (MYFILE, 'auth.log');
while (my $line = <MYFILE>){
if ($line =~ /Failed password/){
$count++;
}
print $count;
#print "$line\n" if $line =~ /Failed password/;
#this was a print test to see if it would only print the failed password strings in the file.
}
close (MYFILE);