猿问

如何使用变量和非过滤器运行ldap搜索?

ldapsearch -h 1.0.24.24 -p 389 -x -t -LLL -S cn -D 

cn=user,ou=resources,o=otherresource,c=xx -w server101 -b ou=Non-

Staff,ou=people,o=test,c=us '(&(objectClass=inetOrgPerson)

(createTimestamp<=$month_8)(!(nEApps=*))(nEDHHSNFAccNbr=\00)

(nECreatedBy=cioSelfRegistered)(loginTime<=$month_3))' dn

如果过滤器用双引号引起来,则只能使用变量;如果过滤器用单引号引起来,则只能使用不过滤器。有没有办法在同一查询中使此工作有效?


拉风的咖菲猫
浏览 240回答 2
2回答

忽然笑

!是交互模式下的特殊字符(它执行命令历史记录替换),而不是脚本中的特殊字符。您应该以交互方式键入此内容,还是将其嵌入脚本中?如果是后者,则可以使用双引号,!这样就不会有问题。如果您以交互方式使用此功能,则有很多选择。一种是将引号模式混入单个参数中,如"double-quoted-section"'single-quoted-section'"another-quoted-section"。这看起来很奇怪,但效果很好。像这样的东西:ldapsearch -h 1.0.24.24 -p 389 -x -t -LLL -S cn \-D cn=user,ou=resources,o=otherresource,c=xx -w server101 \-b ou=Non-Staff,ou=people,o=test,c=us \"(&(objectClass=inetOrgPerson)(createTimestamp<=$month_8)("'!'"(nEApps=*))(nEDHHSNFAccNbr=\00)(nECreatedBy=cioSelfRegistered)(loginTime<=$month_3))" dn&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^^^^^或者,您可以将变量定义为!(使用单引号),然后在双引号内使用该变量:exclamation='!'ldapsearch -h 1.0.24.24 -p 389 -x -t -LLL -S cn \-D cn=user,ou=resources,o=otherresource,c=xx -w server101 \-b ou=Non-Staff,ou=people,o=test,c=us \"(&(objectClass=inetOrgPerson)(createTimestamp<=$month_8)($exclamation(nEApps=*))(nEDHHSNFAccNbr=\00)(nECreatedBy=cioSelfRegistered)(loginTime<=$month_3))" dn&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^^^^^^^^^^^^

慕莱坞森

由于,!过滤器仅“需要”单引号*,shell会尝试将其扩展为通配符。解决方案:逃脱它。
随时随地看视频慕课网APP
我要回答