Expect control statement

I am using expect

I dont know tcl but trying to use a control statement to send requests from an input file - dont know what I am doing to be honest as I dont know tcl and dont use expect too much...

Any help?

See below
Basically I am opening a telnet session to a server which works fine and I can send one command. I want to put several commands in to a file- just an example below.. and the error when I try to run this is below also
ie - file is called test.txt and contains
df -k
ps -ef
ls -ltr /etc/

==============================
# Open a telnet session to a remote server, and wait for a username prompt.
spawn telnet $remote_server
expect "USERCODE:"
# Send the username, and then wait for a password prompt.
send "xxxxxxx\r"
expect "PASSWORD:"
# Send the password, and then wait for a shell prompt.
send "xxxxxxx\r"
expect "<"
# Send the prebuilt command, and then wait for another shell prompt.
send "$my_command\r"

for i in `cat testfm.txt`; send "echo $i\r" ; done
expect "<"
# Capture the results of the command into a variable. This can be displayed, or written to disk.
set results $expect_out(buffer)
# Exit the telnet session, and wait for a special end-of-file character.
send "exit\r"
expect eof

==============================

invalid command name "i"
while executing
"i"
("for" initial command)
invoked from within
"for i in `cat test.txt`"
(file "./.test_script" line 24)

First problem is that your loop is in some kind of bash syntax, and you are in a TCL script.

Try looking here to get an idea on how to write proper FOR loops for expect.

Next problem is that you should be "setting" any TCL variables before you use them... again this is probably because it looks like you are confused between expect and bash...

If all you want to do is execute a series of commands on a telnet session, this is probably the most common example that exists when Googling for it... give 'er a try...

Finally, I leave you with my favorite resource on Expect, here

Enjoy!

Excellent - thanks..

Got some useful tcl information from the below site - exactly what I needed

Tcl Tutorial