title: Modify expect-based SSH script to work on machines that don't require a password
body: <p>The following expect script works fine when the Linux machine asks for a password after login. But some of our Linux machines don't need a password for SSH (we can login without a password), so I need to change the expect script in order to support machines without a password. How can I do that?</p>
  
  <pre><code>$ expect_test=`cat &lt;&lt; EOF
  set timeout -1
  spawn  ssh $IP  hostname
      expect {
                ")?"   { send "yes\r"  ; exp_continue  }
                word:  {send "pass123\r"     }
      }
  expect eof
  EOF`
  
  $ expect -c "$expect_test"
  </code></pre>
  
  <p>When running on a machine that needs a password:</p>
  
  <pre><code> $ IP=10.17.18.6
   $ expect -c "$expect_test"
   spawn ssh 10.17.18.6 hostname
   sh: /usr/local/bin/stty: not found
   This computer system, including all related equipment, networks and network devices     (specifically including Internet access),is pros
   yes
   Password: 
   Linux1_machine
  </code></pre>
  
  <p>When running on a machine that doesn't need a password:</p>
  
  <pre><code>$ IP=10.10.92.26
  $ expect -c "$expect_test"
  spawn ssh 10.10.92.26 hostname
  sh: /usr/local/bin/stty: not found
  Linux15_machine
  expect: spawn id exp5 not open
  while executing
  "expect eof"
  </code></pre>