Skip to content

Instantly share code, notes, and snippets.

@stephdl
Last active November 22, 2018 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephdl/e3f65a0c433c6f1b616eb4215b35f111 to your computer and use it in GitHub Desktop.
Save stephdl/e3f65a0c433c6f1b616eb4215b35f111 to your computer and use it in GitHub Desktop.
delete-users
#!/usr/bin/perl
#
# Copyright (C) 2018 Nethesis S.r.l.
# http://www.nethesis.it - support@nethesis.it
#
# This script is part of NethServer.
#
# NethServer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or any later version.
#
# NethServer 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 NethServer. If not, see <http://www.gnu.org/licenses/>.
#
use strict;
use esmith::event;
use File::Temp qw(tempfile);
my $file = shift;
my $separator = shift;
if($file) {
open(FH, "<", $file) or die;
} else {
open(FH, "-");
}
if( ! $separator) {
$separator = "\t";
}
while(<FH>) {
# Remove trailing whitespace:
chomp $_;
$_ =~ s/\s+$//;
my ($username) = split(/$separator/, $_);
if( ! $username) {
next;
}
if( ! esmith::event::event_signal('user-delete', $username) ) {
warn "[ERROR] Account `$username` user-delete event failed.\n";
next;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment