Perl array remove duplicate values – Update

Great news! I used the function from yesterdays post in a production script today. the script searches a log file on a 60 min basis and grab usernames and passwords, removes the dupes and enters the usernames and passwords to another system.

#! /usr/bin/perl -w

use strict;

sub uniq{
        my %temp_hash = map { $_, 0 } @_;
        return keys %temp_hash;

my @raw_data = `grep ': Password mismatch (given password:' /var/log/maillog`;
my @data;
for (@raw_data){
        my ($username, $password) = /auth: passwd-file\(([^,]+),.*given password: ([^\)]+)\)$/;
        if ($username && $password){
                push @data, "$username\t$password";
@data = &uniq(@data);
my @pgl = `cat /???/?????/???????`;
for (@data){
        my ($username, $password) = split;
        if (grep /^$username\s+/, @pgl){
                system "/bin/ $username $password";
This entry was posted in Perl and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *