【问题标题】:shell script containing ldapmodify - hardcoding commands包含 ldapmodify 的 shell 脚本 - 硬编码命令
【发布时间】:2013-07-24 15:34:48
【问题描述】:

我正在尝试在 shell 脚本中运行 ldapmodify 命令,但我不想指定包含命令的外部文件(-f 标志)。这只是为了方便 - 外部文件中的命令将是动态的,因此最好避免每次 shell 脚本运行 ldapmodify 时都编写新文件。我希望脚本基本上在命令行中输入以下内容:

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)

有人知道怎么做吗?

【问题讨论】:

    标签: linux shell active-directory ldap


    【解决方案1】:

    使用“这里”文档:

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

    例如。

    【讨论】:

    • 你是说看起来像:"ldapmodify -v -H LDAP://111.111.111.11 -D "CN=binding_user,DC=example,DC=com" -x -w password
    • 单独一行的! 表示此处文档的结尾和文件的结尾。
    • 如果这个答案是正确的,它应该被标记为答案。
    【解决方案2】:

    您可以只将文本和管道回显到 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>
    

    【讨论】:

    • “HERE”文档方法效果很好,但是在 bash 脚本的上下文中,它在修改 userPassword 时会引入尾随空格。这种echopipe 方法不会产生尾随空格的副作用。
    【解决方案3】:

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

    【讨论】:

    • 这对我来说是很久以前的事了 - 接受的答案对你不起作用吗?
    • 我刚刚测试了 Terry Gardner HERE 脚本答案。它也可以正常工作。这是 2 个解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 2017-01-19
    • 2014-03-03
    • 1970-01-01
    • 2017-06-02
    相关资源
    最近更新 更多