필자는 작은 변수의 값을 사용하여 ldapsearch 명령을 포맷하고 ldap 서버의 제공된 세부 정보가 올바른지 여부를 확인하기 위해 명령을 실행해야하는 작은 ksh 스크립트를 작성하고 있습니다. 공백이있는 LDAP 사용자에게는 스크립트가 실패합니다. 내가 탈출하면ksh의 문자열 처리
/usr/bin/ldapsearch -x -H ldap://192.168.1.2 -b dc=myldap,dc=com -s sub -o nettimeout=10 -LLL -A -D CN=userwith space,CN=Users,DC=MYLDAP,DC=COM -w Passw0rd '(objectClass=*)' -z1 dn
을 실패
내 스크립트는 스크립트에서 생성되는 위의 스크립트
[[email protected] ~]# /tmp/test
+ username=CN='userwith space,CN=Users,DC=MYLDAP,DC=COM'
+ pswd=Passw0rd
+ cmd='/usr/bin/ldapsearch -x -H ldap://192.168.1.2 -b dc=myldap,dc=com -s sub -o nettimeout=10 -LLL -A '
+ cmd+='-D CN=userwith space,CN=Users,DC=MYLDAP,DC=COM -w Passw0rd'
+ cmd+=' (objectClass=*) -z1 dn'
+ print /usr/bin/ldapsearch -x -H ldap://192.168.1.2 -bdc=myldap,dc=com -s sub -o nettimeout=10 -LLL -A -D CN=userwith space,CN=Users,DC=MYLDAP,DC=COM -w Passw0rd '(objectClass=*)' -z1 dn
/usr/bin/ldapsearch -x -H ldap://192.168.1.2 -b dc=myldap,dc=com -s sub -o nettimeout=10 -LLL -A -D CN=userwith space,CN=Users,DC=MYLDAP,DC=COM -w Passw0rd (objectClass=*) -z1 dn
+ /usr/bin/ldapsearch -x -H ldap://192.168.1.2 -b dc=myldap,dc=com -s sub -o nettimeout=10 -LLL -A -D CN=userwith space,CN=Users,DC=MYLDAP,DC=COM -w Passw0rd '(objectClass=*)' -z1 dn
+ 2> /tmp/ldapfail.tmpwrite
+ retstr=''
+ ret=49
+ print retstr=
retstr=
+ print ret=49
ret=49
+ print '/tmp/ldapfail.tmpwrite : '
/tmp/ldapfail.tmpwrite :
+ [[ 49 -ne 0 ]]
+ print ERROR:--------------
ERROR:--------------
+ cat /tmp/ldapfail.tmpwrite
ldap_bind: Invalid credentials (49)
additional info: 80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1
ldapsearch 명령의
[[email protected] ~]# cat /tmp/test
#!/usr/bin/ksh
set -x
username="CN=userwith space,CN=Users,DC=MYLDAP,DC=COM"
pswd="Passw0rd"
cmd="/usr/bin/ldapsearch -x -H ldap://192.168.1.2 -b dc=myldap,dc=com -s sub -o nettimeout=10 -LLL -A "
cmd+="-D $username -w $pswd"
cmd+=" (objectClass=*) -z1 dn"
print $cmd
retstr="$($cmd 2>/tmp/ldapfail.tmpwrite)"
ret=$?
print "retstr=$retstr"
print "ret=$ret"
print "/tmp/ldapfail.tmpwrite : "
[[ $ret -ne 0 ]] && print "ERROR:--------------" && cat /tmp/ldapfail.tmpwrite
출력 아래 뭔가처럼 보인다 '\'를 사용하여 공간을 명령 줄에서 CN=userwith\ space,CN=Users,DC=MYLDAP,DC=COM
처럼 작동하지만 username="CN=userwith\ space,CN=Users,DC=MYLDAP,DC=COM"
와 스크립트는이 방법 /usr/bin/ldapsearch -x -H ldap://192.168.1.2 -b dc=myldap,dc=com -s sub -o nettimeout=10 -LLL -A -D CN='userwith\' space,CN=Users,DC=MYLDAP,DC=COM -w Passw0rd '(objectClass=*)' -z1 dn
이 문제를 해결하는 방법에 대한 단서에 스크립트 형식 때문에 ldapsearch 명령을 실패
ksh 스크립트에서 작동하지 않는 이유는 무엇입니까?
당신은 스크립트 –