diff --git a/perl-script/user_cleanup.pl b/perl-script/user_cleanup.pl index 4ada3bd..fe36505 100644 --- a/perl-script/user_cleanup.pl +++ b/perl-script/user_cleanup.pl @@ -6,15 +6,27 @@ use strict; my $fn; 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"; open FILE, "<", $fn or die "could not open $fn"; -$cmd_out = `ls /home`; -chomp $cmd_out; - while(){ chomp; - `userdel $_` unless($cmd_out =~ /$_/); + + unless(exists( {map { $_ => 1} @hd}->{$_})){ + printf("Deleting user %s\n", $_); + `userdel $_`; + } } -close FILE; +close FILE