[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: half working script to mass add host



On Monday 27 October 2008 22:03 Holger Levsen wrote:
> 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?

Yes, sure, but why as an example?
It is needed in lwat in the same way as the mass import of users is 
implemented. :-)

>
> #!/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

as in DNS the alias is encoded with 'ldap', so this should be ldap

> BASE=dc=skole,dc=skolelinux,dc=no
> ADMIN=uid=finnarne,ou=People,dc=skole,dc=skolelinux,dc=no

which 'uid' should be used here in *real* and who to create?

> read -s -p "Enter password for user $DN: " PASS

-s doesn't work for me, didn't investigate why ...

>
> LDAPBIND="-D $ADMIDN -w $PASS"

here $ADMIDN should be $ADMIN

> 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

here '-xZD' has an D too much, it was already declared above in 
ADMIN=...

> 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
  ^^^N^^^^^

here the 'gidNumber' should be 10006, IMHO, because that is the correct 
one of machines group in etch tjener standard installs as I proved on 
two machines. May be others can prove that too?
If so, it is a bug in lwat ..., that there will be gidNumber: 107.

> homeDirectory: /dev/null
> EOF
>     smbpasswd -ma $MACHINE

the script needs root rights at this point ...

> done

 ... so far this is IMHO not complete and will not work in real if you 
do not correct it to your own needs. 
And thanks to Finn Arne for his help anyway.

Regards, Jürgen 

-- 
Jürgen Leibner
juergen.leibner@t-online.de
GnuPG Key ID: 0x37FF4410
Finger-Print: CF03 BA85 654D 0EED E161 3DD5 07FF 8246 37FF 4410

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: