Linux 使用 ldapsearch 只返回一个值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20868784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:44:18  来源:igfitidea点击:

using ldapsearch to return only a value

linuxopenldap

提问by Reda

using an OPENLDAPserver i want to retrieve informations from it with ldapsearch. I created a custom class called iduriclass, this class is used to store an id and an uri. in my ldapsearch command i want it to return only the uri for a specified id.

使用OPENLDAP服务器,我想使用ldapsearch从中检索信息。我创建了一个名为iduriclass的自定义类,这个类用于存储一个 id 和一个 uri。在我的 ldapsearch 命令中,我希望它只返回指定 ID 的 uri。

EXAMPLE :the directory contain now two entries id=test uri=server.com/testand id=test2 uri=server.com/test2

示例:目录现在包含两个条目id=test uri=server.com/testid=test2 uri=server.com/test2

Trying it i get an ldiffile that contains all uris in the server

尝试它我得到一个ldif文件,其中包含服务器中的所有 uri

I want to have an ldapsearch command that takes test as argument and returns only a value that is : server.com/test

我想要一个 ldapsearch 命令,它将 test 作为参数并只返回一个值: server.com/test

采纳答案by alvits

Here's how you query your ldap server.

以下是查询 ldap 服务器的方法。

HOSTNAME=<your ladap hostname>
USERNAME=<your ldap username>
PASSWORD=<your ldap username's password>
SEARCHBASE=<your ldap's search base DN>
QUERYSTRING=test1
PORT=<your ldap port>

ldapsearch -LLL -h ${HOSTNAME} -p $PORT -D cn=${USERNAME} -w ${PASSWORD} -b "${SEARCHBASE}" "(id=${QUERYSTRING})" uri | sed -n 's/^[ \t]*uri:[ \t]*\(.*\)//p'

The option -LLLwill not print ldap comments on output. Your ldap may require -x(simple authentication) if it doesn't support SASL.

该选项-LLL不会在输出上打印 ldap 注释。如果您的 ldap-x不支持SASL.

回答by badc0de

Adding the parameter -ttwrites a file with ONLY the requested attribute(s) value as the OP requested. No preceding field name or anything else. Path is configurable with -T, otherwise is /tmp

添加参数-tt写入仅包含请求的属性值作为 OP 请求的文件。没有前面的字段名称或其他任何内容。路径可以用-T配置,否则是/tmp

I write this clarification due to lack of reputation to comment.

由于缺乏评论的声誉,我写了这个澄清。