Looping problem

I need help. I am trying to get this script to send out only one email not multiple emails of the abend. Currently it will send me one then and ther with the first and second one then another email with the first second and third abend and so on. I only want one email sent.

#!/usr/bin/ksh


LIST=/home/B611568/ABC/daren_scripts/temp/tmpfxxx
ERRORDIR=/home/B611568/ABC/error_directory
EMAILFILE=/home/B611568/ABC/daren_scripts/temp/emailfile

echo "There were errors in the following report file :" > $EMAILFILE
echo >> $EMAILFILE
echo "This files have been moved to $ERRORDIR" >>$EMAILFILE
find /home/B611568/ABC/logs/*.rpt -mtime -5 | egrep -v ftplog >$LIST
while read r1
do
grep CompletionCode $r1 >/dev/null 2>&1
#grep severity $r1 | grep "Completion:" >/dev/null 2>&1
if [ $? = 0 ]; then
grep CompletionCode $r1 | grep "CompletionCode: Value=0" >/dev/null 2>$1
#grep severity $r1 | grep "Completion: Value=0" >/dev/null 2>&1
if [ $? = 1 ]; then
echo $r1 >> $EMAILFILE
echo >>$EMAILFILE
#cat $r1 >>$EMAILFILE
mv $r1 $ERRORDIR
for i in `cat /home/B611568/ABC/daren_scripts/emailparm`
do
cat $EMAILFILE | mail -s $r1 $i@xxxxxxx.cccccccccc.org
done
fi
fi
done<$LIST

Not sure I understand. What is an "abend"? And, if you want just one mail, collect all the messages in one file and send that out once after all list entries have been processed, NOT in a loop in a loop.

An abend is IBM mainframe phrasing for ABnormal END, i.e. an error return. I'm showing my age, I'm sure.

You just need to collect the condition/message/alert and run through once. Are you okay to run all the processing and then this report or are you trying to do it real time, hence the extra loop?

Robin