From 2e7f547a27ef30c042b844ceae91c5a30a6daa98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Fri, 3 Dec 2021 09:07:23 +0100 Subject: [PATCH] find highest uid-number and gid-number in ldap --- bin/ldap_createaccount | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 bin/ldap_createaccount diff --git a/bin/ldap_createaccount b/bin/ldap_createaccount new file mode 100755 index 0000000..d15f6c4 --- /dev/null +++ b/bin/ldap_createaccount @@ -0,0 +1,22 @@ +#!/bin/bash + + + +USEROUS=( $(ldapsearch -LLL -Z -H ldap://${LDAP_HOST_DEFAULT} -D ${LDAP_ADMIN_BIND_DN} -x -w $(pass ${PASS_ID_LDAP_ADMIN}|head -n 1) -s one -b ou=users,dc=schuerz,dc=at '(objectClass=organizationalUnit)' ou|grep "^ou"|awk '{print $2}') ) + +for uou in ${USEROUS[@]} ; do + + echo "User OU: $uou" + UID_HIGHEST=$(ldapsearch -LLL -Z -H ldap://${LDAP_HOST_DEFAULT} -D ${LDAP_ADMIN_BIND_DN} -x -w $(pass ${PASS_ID_LDAP_ADMIN}|head -n 1) -b ou=$uou,ou=users,dc=schuerz,dc=at '(&(dcAccountStatus=active)(objectClass=posixAccount))' uidNumber|grep "^uidNumber"|awk '{print $2}'|sort|tail -n1) + GID_HIGHEST=$(ldapsearch -LLL -Z -H ldap://${LDAP_HOST_DEFAULT} -D ${LDAP_ADMIN_BIND_DN} -x -w $(pass ${PASS_ID_LDAP_ADMIN}|head -n 1) -b ou=$uou,ou=users,dc=schuerz,dc=at '(&(dcAccountStatus=active)(objectClass=posixAccount))' gidNumber|grep "^gidNumber"|awk '{print $2}'|sort|tail -n1) + + echo UID_HIGHEST: $UID_HIGHEST + echo GID_HIGHEST: $GID_HIGHEST + + let "UID_HIGHEST=UID_HIGHEST+1" + let "GID_HIGHEST=GID_HIGHEST+1" + + echo UID_NEXT: $UID_HIGHEST + echo GID_NEXT: $GID_HIGHEST + +done