Skip to content

Instantly share code, notes, and snippets.

@javierag
Last active August 29, 2015 14:15
Show Gist options
  • Save javierag/13e64139c55b08ac724b to your computer and use it in GitHub Desktop.
Save javierag/13e64139c55b08ac724b to your computer and use it in GitHub Desktop.
Delete zentyal users by regex
#!/usr/bin/perl
# Copyright (C) 2014 Zentyal S.L.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
use strict;
use warnings;
use EBox;
use EBox::Global;
use EBox::Samba::User;
if (not @ARGV) {
die "Usage: $0 username-regex";
}
my $usernameRe = qr/$ARGV[0]/;
EBox::init();
my $samba = EBox::Global->modInstance('samba');
my @users = @{ $samba->users() };
my $removed = 0;
foreach my $user (@users) {
my $name = $user->name();
if ($name =~ m/$usernameRe/) {
print "Deleting user $name\n";
$user->deleteObject();
$removed+=1;
}
}
print "$removed users deleted\n";
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment