spawn telnet $host expect login: send $user\r expect Password: send $pass\r expect $prompt send "cat $filename\r" log_user 0 expect { ^$prompt { # ... } -re {^([^\r]*)\r\n} { puts "The line is '$expect_out(1,string)'." exp_continue } }
Useful tip if rshell is available to the host. No login and you get only the output of the command.
spawn rsh -s $host $commandtorun expect { \n { puts $expect_out(buffer) exp_continue } eof { puts $expect_out(buffer) } } ;# RJ