Saturday, January 24, 2009

Add user in LDAP Database using Script

Adding the user in LDAP database using the script
 
#!/bin/bash
 
adduser $1
 
passwd $1
 
cat /etc/passwd | grep $1  >> /tmp/changeldappasswd.tmp
 
/usr/share/openldap/migration/migrate_passwd.pl /tmp/changeldappasswd.tmp /tmp/changeldappasswd.ldif.tmp
 
cat /tmp/changeldappasswd.ldif.tmp | sed s/padl/mydomain/ > /tmp/changeldappasswd.ldif
 
ldapadd -f /tmp/changeldappasswd.ldif -x -D "cn=Manager,dc=mydomain,dc=com" -w secret
 
rm -rf /tmp/changeldappasswd.*

OUTPUT: 
ldapadd -f changeldappasswd.ldif -x -D "cn=Manager,dc=mydomain,dc=com" -w secret adding new entry "uid=test,ou=People,dc=mydomain,dc=com"
 
Output of  this script will be like this (if you want to check the temporary files before completion)
 
# cat /tmp/changeldappasswd.ldif
dn: uid=test,ou=People,dc=mydomain,dc=com
uid: test
cn: test
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypt}$1$RilVIlhw$yUZNJ8VpXDxr9xzsOQ6pi1
shadowLastChange: 14268
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 503
gidNumber: 503
homeDirectory: /home/test

2 comments:

piojunbabia said...

hello i like to learn more about linux. i might learn things from you... :)

piojunbabia said...

if it is ok with you..