title: Bash script to search for LDAP entries
body: <p>I have a bash script which is to be used to delete a particular user if it exists in a group.</p>
  
  <p>First I extracted all the group names and saved it to a file. As the next step, I thought I should parse through the file, and use the ldapsearch command on all the entries and grep the user, and if it exists, use ldapmodify to delete it.</p>
  
  <p>My question is how to write the if condition, i.e <code>if [ *ldapsearch query* == True];then</code></p>
  
  <p>This is what my ldapsearch looks like, and the first line inside the while loop is to be the <code>if</code> statement.</p>
  
  <pre><code>while read grp;do
          ldapsearch -w 'ldappass' -D "cn=adminuser,dc=some-domain,dc=com"  -b "cn=$grp,ou=group,dc=some-domain,dc=com"  | grep $someuser
  done&lt;/home/someuser/tempfile.txt
  </code></pre>
  
  <p>On the CLI, this ldapsearch query returns the following output;</p>
  
  <p><code>memberUid: testuser</code></p>
  
  <p>So essentially, if the <code>if</code> statement returns some value (i.e. the user exists), then I have to delete the user. How do I get a correct <code>if</code> statement to get a True or False result for the ldapsearch query?</p>