Expect

I have a file consisting of a list of ip address, one per line, a seedfile if you will.

I have a file name <ip address>.push for each ip address contained in the seedfile

I want to be able to open and read the seedfile assigning the ip to a variable, then open the associated <ip address>.push file and send each line one by one.

this is what I got so far ..

#! /usr/local/bin/expect --
puts "[exec clear]"
# Open Seedfile
#=============================================================
set ifil [open "sss" r]
#
# Main Body. While reading the seedfile, Assign current ip to a variable, use that variable assignment to open the assoicated push file.
#=============================================================
while { [gets $ifil host] >=0 } {
puts "$host\n"
set pfil [open '$host.push' r] THIS IS ACTUALLY THE PROBLEM
#set pfil [open "$host.push" r]
puts "$pfil\n"
}

---------- Post updated at 11:49 AM ---------- Previous update was at 11:16 AM ----------

ok got a little further ...

set ifil [open "listofips" r]
while { [gets $ifil host] >=0 } {
puts "$host\n"
#set f [open $host.push]
set f [open static.push] I want to use the $host var in the filename.
while {[gets $f line] >= 0} {
puts $line
}
close $f
}
close $ifil

The way I usually do this, instead of messing with the seedfile within the expect script, I write a small loop that calls the expect script and passes the variables to it.

So I'd have, say:

# ls
seedfile
loop.ksh
interact.exp

... and loop would be like:

# cat loop.ksh
...
for ipaddress in $(cat seedfile); do  # or while read, whichever you prefer
    interact.exp $ipaddress
done

..while the expect script would look like:

# cat interact.exp
...
spawn ssh [lindex $argv 0]
expect Password:
...