Showing posts with label sample ldap commands. Show all posts
Showing posts with label sample ldap commands. Show all posts

Tuesday, March 2, 2010

Find null attribute and modify on Ldap Server


Language null search


ldapsearch -x -h localhost -p 389 -D cn=root,dc=mycompany,dc=com -w secret -b ou=subscribers,dc=mycompany,dc=com "(!(tnaLanguage=*))" dn | grep dn:

This script gives us the subscribers without having tnaLanguage attribute.
Modify entries having null language

dn: tnaId=2108840497330132510,ou=subscribers,dc=mycompany,dc=com

dn: tnaId=2806900514076119703,ou=subscribers,dc=mycompany,dc=com

dn: tnaId=3602194238187496434,ou=subscribers,dc=mycompany,dc=com

dn: tnaId=2806900514076119725,ou=subscribers,dc=mycompany,dc=com

Compose modifyLanguage.ldif like below

dn: tnaId=807889406294118443,ou=subscribers,dc=mycompany,dc=com

changetype:modify

add: tnaLanguage

tnaLanguage: english


Execute ldif file like below
ldapmodify -x -h localhost -p 389 -D cn=root,dc=mycompany,dc=com -w secret -f modifyLanguage.ldif

Note: You need use cshell for the use of " ! " sign before search operation

Thursday, January 14, 2010

Ldap Operations

LDAP ADD
ldapadd -D "cn=root,dc=mycompany,dc=com" -w secret1 -f allLdif.ldif

LDAP SEARCH
ldapsearch -h localhost -p 389 -D cn='Directory Manager' -w tneu34 -b dc=mycompany,dc=com 'tnaPhoneNumber=380332340400'

INDEX USAGE TEST
ldapsearch -h localhost -p 389 -D cn='Directory Manager' -w tneu34 -b dc=mycompany,dc=com 'tnaPhoneNumber=380933998099' debugsearchindex

LDAP MODIFY
ldapmodify -h localhost -p 389 -D cn=root,dc=mycompany,dc=com -w secret1 -f okanGrep.ldif

LDAP EXPORT
Openldap:ldapsearch -h localhost -p 389 -D cn=root,dc=mycompany,dc=com -w secret1 -b dc=mycompany,dc=com objectClass=* > /tmp/all.ldif
Opends:/export-ldif -h localhost -p 4444 -D "cn=Directory Manager" -w secret1 -X --includeBranch "dc=mycompany,dc=com" --backendID userRoot --ldifFile /space/primaryOpendsExport.ldif

LDAP EXPORT OF SPECIFIC ATTRIBUTE
Openldap exm-1:ldapsearch -x -h localhost -p 389 -D cn=root,dc=mycompany,dc=com -w secret1 -b ou=subscriptions,dc=mycompany,dc=com tnaTotalMessageCountQuota=* dn tnaSubscriptionStatus tnaTotalMessageCountQuota > quotaExport.ldif

Openldap exm-2:ldapsearch -h localhost -p 389 -D cn=root,dc=mycompany,dc=com -w secret1 -b ou=subscriptions,dc=mycompany,dc=com objectClass=* > /tmp/allSubscriptions.ldif

FOUND SUBCOUNT COUNT UNDER A NODE
Opends:ldapsearch -h localhost -p 1389 -D cn='Directory Manager' -w secret1 -b "ou=subscribers,dc=mycompany,dc=com" -s base "objectclass=*" numsubordinates

Getting exact count with scripting

ldapsearch -h localhost -p 1389 -D cn='Directory Manager' -w secret1 -b "ou=subscribers,dc=mycompany,dc=com" -s base "objectclass=*" numsubordinates| grep "numsubordinates:"| cut -c "18-"

FOUNDING OPEN CONNECTIONS
Opends:ldapsearch -h tas5 -p 4444 -D "cn=directory manager" -w secret1 --useSSL --trustAll -s base -b "cn=Client Connections,cn=LDAP Connection Handler 0.0.0.0 port 1389,cn=monitor" "(objectclass=*)"| wc -l
160

EXAMPLE OF BATCH SEARCH ON OPENDS UNDER LINUX
[ennio@serkanslnx ~]# while read line ; do ldapsearch -h localhost -p 389 -D cn=root,dc=mycompany,dc=com -w secret1 -b dc=mycompany,dc=com tnaPhoneNumber=$line; done < unique_in_ldap.txt | grep "dn" >dns.txt

LDAP IMPORT
Opends:import-ldif -n userRoot --skipSchemaValidation -l /space/migration/huge.ldif >import.log &