I am trying to lock out a batch of users. They are all in file "cleanup.txt".
All the users exist in "/etc/shadow". I have made a backup of "/etc/shadow" to
play with.
I cannot figure out why I cannot match users from the file with usernames in
field 0
of "/etc/shadow.bak". I am writing to "newshadow" to be on the safe side.
If the line:
if ($fields[0] eq $user)
were ever true the script would be fine.
Can anyone see what I am doing wrong?
#!/opt/csw/bin/perl
open(SHADOW, "< /etc/shadow.bak");
@shadows = <SHADOW>;
open(NAMES, "< cleanup.txt");
@users = <NAMES>;
close(NAMES);
close(SHADOW);
open(NEWSHADOW, "> newshadow");
LINE: foreach $line (@shadows)
{
@fields = split /:/, $line;
foreach $user (@users)
{
if ($fields[0] eq $user) #this is never true???
{
$fields[1] = '*LK*';
$joined = join(":", @fields);
print NEWSHADOW $joined;
next LINE;
}
}
$joined = join(":", @fields);
print NEWSHADOW $joined;
}
close(NEWSHADOW);
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>