user_cleanup.pl - fixed logic for home_dir => user_list comparison
This commit is contained in:
parent
d4165f1117
commit
40b68f35a6
@ -6,15 +6,27 @@ use strict;
|
|||||||
my $fn;
|
my $fn;
|
||||||
my $cmd_out;
|
my $cmd_out;
|
||||||
|
|
||||||
|
my $dn;
|
||||||
|
my @hd;
|
||||||
|
|
||||||
|
$dn = "/home/";
|
||||||
|
|
||||||
|
opendir MYDIR, $dn or die "could not open $dn";
|
||||||
|
@hd = readdir MYDIR;
|
||||||
|
closedir MYDIR;
|
||||||
|
|
||||||
|
@hd = grep {!($_ =~ /^\..*$/)} @hd;
|
||||||
|
|
||||||
$fn = "/tilde/lyadmin/user_list.txt";
|
$fn = "/tilde/lyadmin/user_list.txt";
|
||||||
|
|
||||||
open FILE, "<", $fn or die "could not open $fn";
|
open FILE, "<", $fn or die "could not open $fn";
|
||||||
|
|
||||||
$cmd_out = `ls /home`;
|
|
||||||
chomp $cmd_out;
|
|
||||||
|
|
||||||
while(<FILE>){
|
while(<FILE>){
|
||||||
chomp;
|
chomp;
|
||||||
`userdel $_` unless($cmd_out =~ /$_/);
|
|
||||||
|
unless(exists( {map { $_ => 1} @hd}->{$_})){
|
||||||
|
printf("Deleting user %s\n", $_);
|
||||||
|
`userdel $_`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
close FILE;
|
close FILE
|
||||||
|
Loading…
Reference in New Issue
Block a user