Perl: Perl script to lock multiple accounts using usermod

The problem was that we have multiple servers with local accounts. The local accounts are required by SOX. Instead of having to type the usermod command every time, this script enables you to enter a userid and just a return to exit. The script can be modified to take a file as an argument. We also use sudo due to SOX requirements.
If the user does not have sudo permissions to perform the usermod command, it will fail.

#! /usr/bin/perl
#This is to lock accounts by adding the userids to an array
#the script will user /usr/sbin/usermod as the mechanism
use strict;
#Lets process the arguments
print "Enter userid followed by RETURN to lock the account. Press RETURN to end script";
local $_;
while (($_ = ) ne "n")
{
{
print ` sudo /usr/sbin/usermod -s /bin/false -L  $_`;
print "Locked $_ n";
}
}
exit();

Mike Kniaziewicz, MIS

Comments are closed.