expect file under while loop

Hello....

I'm developing a script; the first step is to create a file (its name is IP) which contains several lines. The second step is to create and execute expect programs using the data in the (IP) file.

Unfortunately, the loop is executed using the first line only not all the lines and suddenly the execution ends.

The main program is

#!/bin/ksh
#=============================================================================
# This script checks the following:
#  If Active OMCP is synchronized with the NTP source (usually OMC-R)
#  If Other Boards of MX BSC are NTP synchronized with the active OMCP
#  
#
# Valid for BSS versions B9 & B10
#
# Author: Hossam Gad
#=============================================================================

cp /alcatel/omc3/bsscomm/data/mib.ip.decl /alcatel/var/share/AFTR/MISC
cd /alcatel/var/share/AFTR/MISC
sed '/^$/d' mib.ip.decl > draft1
sed -e '1,15d' draft1 > draft2
cut -f2 draft2 > IDdraft
cut -f5 draft2 > IPdraft
sed -e '2d;n;d' IDdraft > ID
sed -e '1d;n;d' IPdraft > IP
while read line
do
echo "#!/usr/local/bin/expect" > program_$line.expect
echo "#!/usr/local/bin/expect" > ftp_$line.expect
echo "set line $line" >> program_$line.expect
echo "set line $line" >> ftp_$line.expect
cat program >> program_$line.expect
cat ftp >> ftp_$line.expect
expect -f program_$line.expect
expect -f ftp_$line.expect
cut -f1 time_difference_OMCPactive >> Active_OMCP
rm time_difference_OMCPactive
done < IP
echo "BSS IDs" > IDs
echo "------" >> IDs
echo "  BSS IPs" > IPs
echo "---------" >> IPs
echo "Active OMCP Drift" > D_ACT_OMCP
echo "---------" >> D_ACT_OMCP
cut -f1 ID >> IDs
cut -f1 IP >> IPs
cut -f1 Active_OMCP >> D_ACT_OMCP
paste IDs IPs D_ACT_OMCP > NTPDRIFT.log
#rm draft1 draft2 IDdraft IPdraft *time_difference* *Active_OMCP* IDs IPs D_ACT_OMCP
cat NTPDRIFT.log

 
program:
spawn ssh mxadmin@$line 
expect {
"yes/no" {send "yes\r"}
}
expect "Password:"
send  "mxadmin\r"
sleep 5
send "su - root\r"
expect "Password:"
send "alcatel\r"
send "/usr/local/NTP/scripts/ntp_supervision.sh -test\r"
send "cp /usr/local/NTP/sup/time_difference /tmp/time_difference_OMCPactive\r"
send "exit\r" 
send "exit\r"
interact
 
ftp:
spawn sftp mxadmin@$line 
expect {
"yes/no" {send "yes\r"}
}
expect "Password:"
send  "mxadmin\r"
expect "sftp>"
send "cd /tmp\r"
expect "sftp>"
send "get time_difference_OMCPactive\r"
expect "sftp>"
send "bye\r"
interact