Expect script ran inside of while loop exits after processing one line
<p>I have a while loop as such:</p>

<pre><code>#!/bin/bash

doit="/pathtocommand"
file="/pathtosourcefile"

while read -r username password; do

$doit "$username" "$password"

done &lt; $file
</code></pre>

<p>And my while loop command ($doit)is an expect script. </p>

<pre><code>#!/usr/bin/expect -f 

## Set up variables to be passed in as command line arguments
#set username [lindex $argv 0];
#set password [lindex $argv 1];
lassign $argv username password

spawn telnet 192.168.100.101 106
expect "200 PWD Server ready"    
send "USER user\r"
expect "300 please send the PASS"
send "PASS password\r"
expect "200 login OK, proceed"

## Use the line below for passwords that do not have to be enclosed    with quotes
send "SETACCOUNTPASSWORD $username PASSWORD $password\r"

# Use the line below for a password that must be quoted ie one that    contains a $ or a ! by escaping the double quotes
#send "SETACCOUNTPASSWORD $username PASSWORD \"$password\"\r"

expect "200 OK"
send "quit\r"
interact
</code></pre>

<p>The expect script should run as many times as there are lines in my file. But it stops after the first line is processed. I am fairly confident that its something in the expect script because changing the command to something like echo works.  </p>

<p>If I debug the script I see this:</p>

<pre><code>+ doit=/pathtocommand
+ file=/pathtofile
+ read -r username password
+ /pathtofile 0100    01000100
spawn telnet 192.168.100.101 106
Trying 192.168.100.101...
Connected to 192.168.100.101.
Escape character is '^]'.
200 PWD Server ready  
USER user
300 please send the PASS
PASS pass
200 login OK, proceed
SETACCOUNTPASSWORD 0100 PASSWORD 01000100
200 OK
quit
+ read -r username password
</code></pre>

<p>It looks to me like the script tries to start over but then simply exits. Can anyone help? I am in a crunch to get this thing working. I have done this before with SSH no problem. Not sure if its a telnet thing or what. </p>