Your script looks like it would send one email per ldap suffix that has a problem - and that's the issue right?
I think you are wanting one email containing a list of all the failing suffixes?
In which case, try this:
Code:
#!/bin/sh
errors=""
while read i
do
ldapsearch -h server1 -b "$i" objectclass=* ibm-replicationState |grep ibm-replicationState=ready > /dev/null 2>&1 || errors="${errors}
${i}"
done <ldaplist
if [ -n "$errors" ]
then
echo $errors | mailx -s "LDAP sync alert on `hostname`" u@mail.com 2>&1
fi
(Untested)
BTW, The linefeed between errors} and ${i}" is not accidental, you want that in there