# ldapsearch bash script help

**URL:** <https://community.unix.com/t/ldapsearch-bash-script-help/275537>\
**Category:** Red Hat\
**Created:** [October 19, 2010, 2:09am UTC](https://community.unix.com/t/ldapsearch-bash-script-help/275537 "2010-10-19T02:09:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![theboogymaster](https://community.unix.com/user_avatar/community.unix.com/theboogymaster/32/1625_2.png) [@theboogymaster](https://community.unix.com/u/theboogymaster)\
**Post date:** [October 19, 2010, 2:09am UTC](https://community.unix.com/t/ldapsearch-bash-script-help/275537/1 "2010-10-19T02:09:35Z")

</div>

Hi there everyone. I'm trying to make a bash script that accepts some arguments ans give's back some info about LDAP users and servers.

I have this function :

```nohighlight
has_group_access(){

result=$(ldapsearch -LLL "cn=${GROUP_NAME}" cn member | cut -d"," -f1 | cut -d":" -f2 | cut -d"=" -f2 | grep -v ${GROUP_NAME} | grep -v ${dummy})

          for item in $result
          do
                  if ["$item" == $(hostname)];then
                          echo "Le groupe:[${GROUP_NAME}] a l'acces sur la machine:[$(hostname)]"
                          echo "\n"
                 else
                         echo "Le group : [${GROUP_NAME}] n'as pas acces sur cette machine"
                  fi
          done
          #echo ${result}
          exit 0
 }

```

What I want is to search in the return value if the hostname (the actual server that executes the script) is in the list.  
And if it is it means that the group can access this machine.

How can I do that ?  
Thank you for your help.  
This is rely important for my job.

---------- Post updated 10-19-10 at 08:09 AM ---------- Previous update was 10-18-10 at 04:06 PM ----------

And how can I query the LDAP server for all the users to see the hosts that they have access to, and after parse this info to show all the users that have access to the running system that will execute the script ?

Thank you for your help

---

<div class="post-metadata">

**Author:** ![zaxxon](https://community.unix.com/user_avatar/community.unix.com/zaxxon/32/660_2.png) [@zaxxon](https://community.unix.com/u/zaxxon)\
**Post date:** [October 19, 2010, 2:28am UTC](https://community.unix.com/t/ldapsearch-bash-script-help/275537/2 "2010-10-19T02:28:35Z")

</div>

Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the [Emergency UNIX and Linux Support Forum](http://www.unix.com/emergency-unix-linux-support-help-me/). This forum is given a higher priority than our regular forums.

Posting a new question in the [Emergency UNIX and Linux Support Forum](http://www.unix.com/emergency-unix-linux-support-help-me/) requires forum [Bits](http://www.unix.com/credits.php?do=banking). We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.
