#!/usr/bin/perl =pod =head1 NAME resetuserlogon.pl =head1 SYNOPSIS perl resetuserlogon.pl =head1 DESCRIPTION This script will check and then reset the invalid logon count and unlock the users account. =head1 AUTHOR TechFly Version: 1.0 Date: 2-9-2011 =cut use warnings; use strict; use IO::Prompt; use Net::SSH::Expect; #Variable declarations if (@ARGV != 2) { print ("\nUseage: resetuserlogon.pl \n"); print ("Please review your arguments.\n\n"); exit 1; } my $servername = $ARGV[0]; my $username = $ARGV[1]; #IO::Prompt uses ARGV to assign the input. You have to clear ARGV before you can use IO::Prompt. pop @ARGV; pop @ARGV; my $password = prompt "Please enter the root password for $servername: ", -e => '*'; my $ssh = Net::SSH::Expect->new ( host=> $servername, password=> $password, user=> 'root', raw_pty=> 1 ); my $sshlogin = $ssh->login(); print("\nUnlocking user account: $username\n"); print("On server: $servername\n\n"); my $listsec = $ssh->exec("lssec -f /etc/security/lastlog -a \"unsuccessful_login_count\" -s $username"); my $accountlocked = $ssh->exec("lsuser -a account_locked $username"); my @listsecsuccede = split(/=|\n/, $listsec); chomp($listsecsuccede[1]); if ($listsecsuccede[1] != 0) { print("The account has $listsecsuccede[1] unsuccessful logon attempts.\n"); if ($ssh->exec("chsec -f /etc/security/lastlog -a \"unsuccessful_login_count=0\" -s $username")) { print(" The unsuccessful logon count was reset.\n") } else { print("The unsuccessfull logon count was NOT reset\n"); } } else { print("The account $username does not have any unsuccessful logon attempts.\n"); } my @listaccountlocked = split(/=|\n/, $accountlocked); if ($listaccountlocked[1] =~ /^true$/i) { print("The account is currently locked.\n"); $ssh->exec("chuser account_locked='false' $username"); if ($ssh->exec("lsuser -a account_locked $username")){ print(" The account was successfully unlocked.\n"); } else { print("The account was NOT successfully unlocked.\n"); } } else { print("The account $username is not locked.\n"); } print("\n\n"); $ssh->close();