對於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);
就移到高於'$打印算你撐;'。您在整個日誌讀數中打印計數。縮進幫助! – squiguy 2013-03-15 03:56:18