I am trying to write a script that will declare txt file & a specified server, run an LDAP query, and put the output in the txt file, but I am getting an error DNS SRV: out of memory? It is a CentOS 7 VM and has 8GB RAM.
#!/bin/bash -x
# Declare vars
outFile="file/path"
dc="my.dc.com"
# Run openldap query
hosts=$(ldapsearch -b "ou=my,dc=ou,dc=path" -H ldap://{$dc} | grep dNSHostName)
# echo to file to test
echo {$hosts} >&2 {$outFile}
exit 0
This is the output I get:
+ outFile=file/path
+ dc=my.dc.com
++ ldapsearch -b "ou=my,dc=ou,dc=path" -H 'ldap://{my.dc.com}'
++ grep dNSHostName
DNS SRV: out of memory?
+ hosts=
+ echo '{}' '{file/path}'
{} {file/path}
+ exit 0
However, when I run just the LDAP query outside of the script, it returns successfully.
The dc has 16GB of RAM. I monitored the RAM during the query and no visible spikes were observed.
EDIT:
[prompt]$ ldapsearch -b "ou=my,dc=ou,dc=path" -H ldap://my.dc.com | grep dNSHostName
SASL/GSSAPI authentication started
SASL username: user@domain.com
SASL SSF: 256
SASL data security layer installed.
dNSHostName: hostname1.com
dNSHostName: hostname2.com
dNSHostName: hostname3.com
dNSHostName: hostname4.com
dNSHostName: hostname5.com
dNSHostName: hostname6.com
dNSHostName: hostname7.com