title: Linux expect command without interact directive not working
body: <p>I want to login from <code>192.168.119.128</code> to <code>192.168.119.129</code> automatic and run some commands, so I write an expect script.</p>
  
  <p><strong>a.sh</strong></p>
  
  <pre><code>#!/usr/bin/expect -f
  
  set timeout 5
  spawn ssh root@192.168.119.129
  expect "password" {send "123456\r"}
  expect "]#" {send "touch /tmp/a.txt\r"}
  #interact
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>kaiwen@kaiwen-virtual-machine:~/Work$ ./a.sh 
  spawn ssh root@192.168.119.129
  root@192.168.119.129's password: 
  Last login: Sun Jan 22 17:36:21 2017 from 192.168.119.128
  [root@localhost ~]# kaiwen@kaiwen-virtual-machine:~/Work$
  </code></pre>
  
  <p>I login successfuly, but it seems <code>touch /tmp/a.txt</code> command is not run.</p>
  
  <p>When I uncomment the last line <code>#interact</code> of <strong>a.sh</strong>, it works, and the file a.txt is created.</p>
  
  <pre><code>#!/usr/bin/expect -f
  
  set timeout 5
  spawn ssh root@192.168.119.129
  expect "password" {send "123456\r"}
  expect "]#" {send "touch /tmp/a.txt\r"}
  interact
  </code></pre>
  
  <p>Here is the output:</p>
  
  <pre><code>kaiwen@kaiwen-virtual-machine:~/Work$ ./a.sh 
  spawn ssh root@192.168.119.129
  root@192.168.119.129's password: 
  Last login: Sun Jan 22 17:41:23 2017 from 192.168.119.128
  [root@localhost ~]# touch /tmp/a.txt
  [root@localhost ~]#
  </code></pre>
  
  <p>Why without the <code>interact</code> directive the script work incorrect? Thanks.</p>