title: how can i read data from a file in expect script
body: <pre><code>#! /bin/expect   
  set timeout 20 
  set user [lindex $argv 0] 
  set password [lindex $argv 1] 
  set prompt "$ "  ;# -- main activity   
  proc dostuff { currenthost} {      
  ;# do something with currenthost      
  send -- "ls -lrt\r"   return}   ;# -- start of task
  
  set fd [open ./hostlist r] 
  set hosts [read -nonewline $fd] 
  close $fd 
  
  foreach host [split $hosts "\n" ] {       
  spawn /usr/bin/ssh $user@$host       
    while (1) {         
      expect { 
          "no)? " {            
          send -- "yes\r"        
      }                  
      "password: " {             
          send -- "$password\r"        
      }                   
      "$prompt" {            
          dostuff { $host }            
          break        
      }       
       }    
    } 
  
  expect "$prompt"   
  send -- "exit\r"  
  }   
  expect eof  
  </code></pre>
  
  <p>I looked through <a href="http://kahimyang.info/kauswagan/howto_blogs/704-using_expect_script_to_automate_ssh_logins_and_do_routine_tasks_accross_multiple_hosts" rel="nofollow">this</a> code online but will it read data if it is arragnged in 2 columns like.</p>
  
  <pre><code>HOST   TFTP_SERVER_ADDRESS
  xx     XXYY
  aa     AABB
  ...    ...
  ...    ....
  </code></pre>
  
  <p>and so on</p>
  
  <p>I would like to assign each TFTP_SERVER_ADDRESS to a variable and use it in my script.</p>
  
  <p>furthermore,Is this piece of code secure :</p>
  
  <pre><code># grab the password
  stty -echo
  send_user -- "Password for $user@$host: "
  expect_user -re "(.*)\n"
  send_user "\n"
  stty echo
  set pass $expect_out(1,string)
  
  #... later
  send -- "$pass\r"
  </code></pre>