Wednesday, September 17, 2014

Bulk Load LDAP / eDirectory Users

Just a simple BASH script to load users.
 #!/bin/bash  
 FILE_WITH_NAMES="names.txt"  
 LDAP_SRV="localhost"  
 LDAP_PORT="389"  
 ADMIN_DN="cn=admin,ou=sa,o=system"  
 ADMIN_PASSWD="novell"  
 USR_BASEDN="ou=users,o=data";  
 USR_PASSWD="novell";  
 LDIF="/tmp/bulkuser.ldif"  
 cat $FILE_WITH_NAMES | while read line  
 do  
      #trim trailing white space and clean  
      fullname=`echo $line | tr -cd '[:print:]\n' | sed -e 's/^ *//' -e 's/ *$//'`  
      stringarray=($fullname)  
      fn=${stringarray[0]}  
      sn=${stringarray[1]}  
      #replace spaces with .       
      CN="${fullname/ /.}"  
   echo "dn: cn=$CN,$USR_BASEDN" > $LDIF  
   echo "cn: $CN" >> $LDIF      
      echo "uid: $CN" >> $LDIF  
      echo "fullName: $fullname" >> $LDIF         
      echo "sn: $sn" >> $LDIF  
      echo "givenName: $fn" >> $LDIF  
      echo "Language: ENGLISH" >> $LDIF  
   echo "userPassword: $USR_PASSWD" >> $LDIF  
   echo "objectClass: top" >> $LDIF  
   echo "objectClass: user" >> $LDIF  
   ldapmodify -x -h $LDAP_SRV -p $LDAP_PORT -D "$ADMIN_DN" -w $ADMIN_PASSWD -a -f $LDIF  
 done  
Input file (names.txt) should contain a full name on each line e.g.
 Boyce Deforge    
 Allan Giard    
 Niesha Orozco    
 Fran Garneau    
 Valda Wotring    
Can use this site to get random names: http://listofrandomnames.com/index.cfm?textarea

No comments:

Followers