Browse Source

user_cleanup.pl - fixed logic for home_dir => user_list comparison

gasha-branch
gashapwn 3 years ago
parent
commit
40b68f35a6
1 changed files with 17 additions and 5 deletions
  1. +17
    -5
      perl-script/user_cleanup.pl

+ 17
- 5
perl-script/user_cleanup.pl View File

@@ -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(<FILE>){
chomp;
`userdel $_` unless($cmd_out =~ /$_/);

unless(exists( {map { $_ => 1} @hd}->{$_})){
printf("Deleting user %s\n", $_);
`userdel $_`;
}
}
close FILE;
close FILE

Loading…
Cancel
Save