Hi,
Finn-Arne gladly posted this script to paste.debian.net, to mass add hosts to
ldap. As it got lost on paste.debian.net I post it here, so someone can take
it and finish the last bits for polishing (ie, it has the uid=finnarne
hardcoded :)
Finn-Arne, do I assume correctly it's gpl2+ licenced?
Should I open a wishlist ticket, that it gets included as example into lwat?
#!/bin/sh
test -z "$1" && echo "Need a filename" && exit 0
test -f "$1" || echo "Need a readable file"
test -f "$1" || exit 0
LDAP=skole
BASE=dc=skole,dc=skolelinux,dc=no
ADMIN=uid=finnarne,ou=People,dc=skole,dc=skolelinux,dc=no
read -s -p "Enter password for user $DN: " PASS
LDAPBIND="-D $ADMIDN -w $PASS"
nextID=$(ldapsearch -xLLL -h $LDAP -b $BASE cn=nextID gidnumber |
awk '/gidNumber:/ { print $2 }')
for MACHINE in $(cat $1) ; do
while ldapsearch -xLLL -h $LDAP -b $BASE "(|(uidNumber=$nextID)
(gidNumber=$nextID))" dn | grep -q ^dn: ; do
nextID=$(($nextID + 1))
done
ldapadd -xZD $ADMIN -w $PASS -h $LDAP << EOF
dn: cn=$MACHINE,ou=Machines,ou=People,dc=skole,dc=skolelinux,dc=no
cn: $MACHINE
objectClass: posixAccount
objectClass: top
objectClass: organizationalRole
uid: $MACHINE$
uidNumber: $nextID
gidnumber: 107
homeDirectory: /dev/null
EOF
smbpasswd -ma $MACHINE
done
regards,
Holger
Attachment:
pgpqUpWPn6Poi.pgp
Description: PGP signature