5

I'm trying to run an ldapmodify command in a shell script, but I don't want to specify an external file containing commands (-f flag). This would just be for convenience - the commands in the external file would be dynamic, so it would be nice to avoid writing a new file every time the shell script ran ldapmodify. I would want the script to essentially enter the following into the command line:

prompt/> ldapmodify -v -H LDAP://111.111.111.11 -D "CN=binding_user,DC=example,DC=com" -x -w password
> dn: CN=group_name, OU=Groups, DC=example, DC=com
> changetype: modify
> add: member
> member: CN=Smith\, John, OU=Users, DC=example, DC=com
> (user presses Ctrl-D)

Anyone know of how to do this?

4

3 回答 3

11

使用“这里”文档:

ldapmodify .. <<!
dn: dc=example,dc=com
changetype: modify
replace: description
 -
add: description
description: The new description
!

例如。

于 2013-07-24T15:58:31.803 回答
3

您可以将文本和管道回显到 ldapmodify,如下所示:

echo "dn: CN=group_name, OU=Groups, DC=example, DC=com
changetype: modify
add: member
member: CN=Smith\, John, OU=Users, DC=example, DC=com" | \
ldapmodify -h <server:port> -D "cn=binding_user,DC=example,DC=com" -c -x -w <password>
于 2013-11-07T20:48:36.327 回答
0

n2studio 是 100% 正确的。“回声”对我有用。还使用“.. | sudo ldapmodify ...”进行了测试,请标记为答案。(我不被允许评论,没有得到 50 分。)

于 2017-04-18T21:38:35.893 回答