title: Using if/else in expect script
body: <p>I recently updated and reformatted my /etc/hosts file and would like to run through every system (roughly 1000) to refresh my known_hosts file. I'm looking at using an expect script to send "yes" to the RSA fingerprint question. Simple enough. However, I know some of these systems are completely new to me and my password has not been set. This creates two possibilities:</p>
  
  <ol>
  <li><p>"yes" is sent to the RSA fingerprint question and I'm logged into
  the server. I'll then need to send an exit to close the connection
  before moving onto the next host. Or...</p></li>
  <li><p>"yes" is sent to the RSA fingerprint question and I'm presented with
  the prompts to update my password starting with the current and
  followed by the new password entered twice. The connection will
  automatically close after the password is updated moving onto the
  next host.</p></li>
  </ol>
  
  <p>I think I have a basic grasp of the concept of "if/else" in expect, but I don't fully understand how to nest them, if there is a better way, or if I'm completely off-base to begin with.</p>
  
  <p>This is what I have right now:</p>
  
  <pre><code>set file1 [open [lindex $argv 0] r]
  
  set pw1 [exec cat /home/user/.pw1.txt]
  set pw2 [exec cat /home/user/.pw2.txt]
  
  while {[gets $file1 host] != -1} {
  
      puts $host
      spawn -noecho "ssh $host"
      expect {
          "continue connecting"{
              send "yes\r"
              expect {
                  "current" {
                      send $pw2\r
                  } "New password" {
                      send $pw1\r
                  } "Retype new password" {
                      send $pw1\r
                  }
              }
          expect "msnyder"
          send "exit\r"
      }
      interact
  }
  </code></pre>
  
  <p>The file1 variable is the list of hosts to run the script against.</p>
  
  <p>I know it isn't accurate because it errors on line 22. But, I have no idea what needs to be fixed.</p>