title: How to run eval spawn ssh and expect in background?
body: <p>I created a script to get in inside an Access Point (AP) using <code>ssh</code> and execute some commands and I used <code>expect</code> to interact with shell.</p>
  
  <p>The scripts works fine when it is running on foreground, but when I try to execute the same script in background using <code>&amp;</code> to fork the process, it stop at <code>spawn ssh</code> command at <code>ap_commands</code> script below.</p>
  
  <p>Trying to execute:</p>
  
  <pre><code>$ run_ap &amp;
  </code></pre>
  
  <p>Bash script (<code>run_ap</code>) to call the expect script:</p>
  
  <pre><code>#!/bin/sh
  while(true); do
      /script/ap_commands
  done
  </code></pre>
  
  <p>Tcl and expect script (<code>ap_commands</code>):</p>
  
  <pre><code>#!/usr/bin/expect
  eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user@192.168.92.1
  
  #use correct prompt
  set prompt ":|#|\\\&gt;"
  set user   "&gt;"
  
  interact -o -nobuffer -re "Password:" return
  send "pass12345\r"
  </code></pre>
  
  <h1>Update 1 - Solution</h1>
  
  <p>Thanks to Donal Fellows, I solved using the screen command who it creates a new terminal and execute the script in foreground.</p>
  
  <pre><code>screen -dm bash ./run_ap
  </code></pre>
  
  <p>and I add <code>-f</code> arguments to <code>expect</code>, to force to run in foreground:</p>
  
  <pre><code> #!/usr/bin/expect -f
  </code></pre>