Show Table of Contents
A.6. Comparing Entries
ldapcompare checks entries to see if the specified entry or entries contain an attribute of a specific value. For example, this checks to see if an entry has an sn value of Smith:
ldapcompare -D "cn=directory manager" -w secret -p 389 -h server.example.com -x sn:smith uid=bjensen,ou=people,dc=example,dc=com comparing type: "sn" value: "smith" in entry "uid=bjensen,ou=people,dc=example,dc=com" compare FALSE ldapcompare -D "cn=directory manager" -w secret -p 389 -h server.example.com -x sn:smith uid=jsmith,ou=people,dc=example,dc=com comparing type: "sn" value: "smith" in entry "uid=jsmith,ou=people,dc=example,dc=com" compare TRUE
The compare attribute can be specified in one of three ways:
- A single attribute:value statement passed in the command line directly
sn:Smith
- A single attribute::base64value statement passed in the command line directly, for attributes like
jpegPhotoor to verify certificates or CRLsjpegPhoto:dkdkPDKCDdko0eiofk==
- An attribute:file statement that points to a file containing a list of comparison values for the attribute, and the script iterates through the list
postalCode:/tmp/codes.txt
The compare operation itself has to be run against a specific entry or group of entries. A single entry DN can be passed through the command line, or a list of DNs to be compared can be given using the
-f option.
Example A.1. Comparing One Attribute Value to One Entry
Both the attribute-value comparison and the DN are passed with the script.
ldapcompare -D "cn=directory manager" -w secret -p 389 -h server.example.com -x sn:smith uid=jsmith,ou=people,dc=example,dc=com comparing type: "sn" value: "smith" in entry "uid=jsmith,ou=people,dc=example,dc=com" compare TRUE
Example A.2. Comparing a List Attribute Values from a File
First, create a file of possible
sn values.
jensen johnson johannson jackson jorgenson
Then, create a list of entries to compare the values to.
uid=jen200,ou=people,dc=example,dc=com uid=dsj,ou=people,dc=example,dc=com uid=matthewjms,ou=people,dc=example,dc=com uid=john1234,ou=people,dc=example,dc=com uid=jack.son.1990,ou=people,dc=example,dc=com
Then run the script.
ldapcompare -D "cn=directory manager" -w secret -p 389 -h server.example.com -x sn:/tmp/surnames.txt -f /tmp/names.txt comparing type: "sn" value: "jensen" in entry "uid=jen200,ou=people,dc=example,dc=com" compare TRUE

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.