Need help using expect in shell scripts

hi all,

i have this script that accepts passwords automatically and its working in one host only. my problem is how will i use it if i need it to run in more than one host/server let say by using "for loop statement"

working :

  spawn bundle linux -r hostname checkpath /opt/home/support/.k5login
  expect "password:"
  send "xxxxyyyy0f!\r"
  interact

not working:

!/usr/bin/expect -f
for i in `awk '{print $1}' server_list`
do
     echo $i
     spawn bundle linux -r $i checkpath /opt/home/support/.k5login
     expect "password:"
     send "xxxyyyy!\r"
     interact
done

here is an error:

----
[root@kickstart SE]# ./ray1.sh
can't read "1": no such variable
while executing
"for i in `awk '{print$1}' server_list`"
(file "./ray1.sh" line 2)
-----

appreciate much your reply on this.

please confirm that the first line reads

#!/usr/bin/expect -f

actually - I just re-read your code. You cannot embed shell script constructs in an expect script. You must use TCL constructs.

ah i see... thanks frank, i will check then the TCL construct.

tnx tnx!

---------- Post updated at 02:55 PM ---------- Previous update was at 11:50 AM ----------

i need extended help for the equivalent of the ff statement:

for i in `awk '{print $1}' server_list` or

server_list=`cat $1`
for i in server_list
do
blah blah
....
done

how will i do this in TCL ?