Hi -
Trying to take a list of ldap suffixes in a file, run an ldapsearch command on them, then run a grep command to see if it's a match, if not, then flag that and send an email alert.
The list file (ldaplist) would look like -
***********
o=company a
o=company b
***********
** Note there are spaces in that file that need to be preserved. I was trying to use a for loop and someone suggested a while read loop in order to prevent the space from being treated as a line break.
The problem w/ the script i created below is that it runs and only sends one email w/ the info from both entries in ldaplist. It's like my nested 'if' loop is not the right loop to use. I made it so that both entries should have 0 return codes and no luck. Runs once and that's it. Any suggestions to a better structure to this? I would try to use a for i in cat /ldaplist - do .... - but that fails because it doesn't treat the space in the ldaplist (ie: o=company a) as a space - even with " ".
while read i
do
ldapsearch -h server1 -b "$i" objectclass=* ibm-replicationState |grep ibm-replicationState=ready > /dev/null 2>&1
if [ $? -ne 0 ]; then
mailx -s "LDAP sync alert on `hostname`"
u@mail.com 2>&1
fi
done <ldaplist
Thanks!