Skip to content
Snippets Groups Projects
Verified Commit 78c44f11 authored by David Beniamine's avatar David Beniamine
Browse files

Script to delete users

parent 7b16123e
Branches
No related tags found
No related merge requests found
#!/bin/bash
# Copyright (C) 2018 Tetras Libre <Contact@Tetras-Libre.fr>
# Author: Beniamine, David <David.Beniamine@Tetras-Libre.fr>
#
# This program 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
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
usage(){
echo "Usage $0 [uids.txt]"
echo "Reads a list of name corresponding to some ldap users"
echo "and remove each of them"
echo "If the list is not specified, prompt for removing all Primtux users"
}
if [ -z "$1" ]
then
read -p "Do you actually want to remove all Primtux users [yes/No] ?" ans
if [ "$ans" != "yes" ]
then
echo "Aborting on user request"
usage
exit 1
fi
set -x
file="$$-uids.txt"
ldapsearch -x cn=Primtux | awk '/^memberUid/{print $2}' > $file
else
if [ ! -f "$1" ]
then
echo "$1 is not a file"
usage
exit 1
fi
file="$1"
fi
rm -f uids.txt
scriptbinpath="/usr/share/lcs/sbin"
if [ ! -x $scriptbinpath/userDel.pl ]
then
echo "Critical error : $scriptbinpath/userDel.pl does not exist or is not executable"
exit 1
fi
while read uid
do
echo "Deleting user $uid"
$scriptbinpath/userDel.pl $uid
done < $file
#rm -f $$-uids.txt
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment