Listing 1. Sample Perl Script for Finding Authentication Errors

#!/usr/bin/perl
open(IN, '/var/log/messages');
@buffer = <IN>;
close IN;

foreach $line (@buffer) {
    if ($line =~ /authentication failure/) {
        $line =~ /^([a-zA-Z]{3} [ 0-9]+
        [0-9:]*).*logname=([a-zA-Z0-9]*).*user=
        ([a-zA-Z0-9]*)$/;
    print "$2 attempted to log in as $3 on $1\n";
    }
}