如何从 ldapsearch 输出中提取属性

如何从 ldapsearch 输出中提取属性

我有一个 ldap 目录,其中包含名为 的类的一些实例store,如下所示:

# ldapsearch -LLL -x -b "utente=las,dc=labammsis" -s base
dn: utente=las,dc=labammsis
objectClass: store
utente: las
indirizzo: 10.1.1.1
chiave: ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAA
 CFBAHTwDePWTXkV32Ggso3fxFHqJ9iPbiAiZ5TadkCIv1gF6GGVsHBUtfq+OuGwOCaDAdi/FXuxt2
 5Be4K0NGlmkwPvABaT3O6pXvA2ucUNzRm/dPME+kwMPc2lWT2MYOnjZ6TBiMl/PVXqHLREZjEJNDX
 4nW6C+7SgGA4d0FGIB+wKEy1gg== las@Client
modificato: 1

我只想提取 type 的属性chiave,因此所需的输出是这样的:

ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBAHTwDePWTXkV32Ggso3fxFHqJ9iPbiAiZ5TadkCIv1gF6GGVsHBUtfq+OuGwOCaDAdi/FXuxt25Be4K0NGlmkwPvABaT3O6pXvA2ucUNzRm/dPME+kwMPc2lWT2MYOnjZ6TBiMl/PVXqHLREZjEJNDX4nW6C+7SgGA4d0FGIB+wKEy1gg== las@Client

搜索网络我发现这个有用的链接,所以我能够这样做:

# ldapsearch -LLL -x -b "utente=las,dc=labammsis" -s base chiave
dn: utente=las,dc=labammsis
chiave: ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAA
 CFBAHTwDePWTXkV32Ggso3fxFHqJ9iPbiAiZ5TadkCIv1gF6GGVsHBUtfq+OuGwOCaDAdi/FXuxt2
 5Be4K0NGlmkwPvABaT3O6pXvA2ucUNzRm/dPME+kwMPc2lWT2MYOnjZ6TBiMl/PVXqHLREZjEJNDX
 4nW6C+7SgGA4d0FGIB+wKEy1gg== las@Client

不错,但不完全是我想要的。

有没有办法仅通过某些参数来实现我的目标,ldapsearch或者我应该操纵输出以获得所需的输出?

答案1

您可以使用 禁用换行-o ldif-wrap=no,之后它仅过滤输出,例如使用sed

ldapsearch -LLL -x -b "utente=las,dc=labammsis" -s base -o ldif-wrap=no chiave \
| sed -ne 's/^chiave: //p'

相关内容