[Date Prev][Date Next] [Chronological] [Thread] [Top]

Get Max uidNumber ...

Greetings ...

I search the archives and found that there was a few ideas how to do this, so I thought that I would though out my idea and see you guys bash it ... no pun intended ... I know this would be slow if one was tring to bring in more than a few users, but then I use it just to add a few users at a time ... I also believe this would not be a good idea to have more than one user adding in users, because the uidNumber could go up while we import the next user.

	Take look and tell me what you think ...


ldapsecret="-w topsecret"
ldapDN="dc=foobar, dc=com"

function getMaxUid ()
for i in $(ldapsearch -x -LLL $ldapsecret -D "cn=Manager, $ldapDN" "(uidNumber=*)" uidNumber -S uidNumber | grep uidNumber | tail -n1 );
do \
let n+=1

    if [ "${ldaparry[0]}" == "uidNumber:" ]; then
	echo $((${ldaparry[1]}+1))
	return 0
	return -1

function adduser () { echo "dn: uid=tempacc,ou=People,$ldapDN" echo "uid: tempacc" echo "cn: tempacc" echo "sn: surname" echo "objectClass: person" echo "objectClass: organizationalPerson" echo "objectClass: inetOrgPerson" echo "objectClass: account"openldap-software@OpenLDAP.org echo "objectClass: posixAccount" echo "objectClass: top" echo "objectClass: shadowAccount" echo "userPassword:: e2NyeXB0fVNBMDFWamZva2VwUi4=" echo "shadowLastChange: 11159" echo "shadowMax: 99999" echo "shadowWarning: 7" echo "gidNumber: 100" echo "homeDirectory: /home/users/tempacc" uidNumber=`getMaxUid` (($uidNumber > 0)) if [ $? ]; then echo "uidNumber: $uidNumber" return 0 else return -1 fi }

adduser | ldapadd -x $ldapsecret -D "cn=Manager, $ldapDN

exit 0