title: Running ssh script with background process
body: <p>Below is a simple example of what I'm trying to accomplish. I'm trying to force an ssh script to not wait for all child processes to exit before returning. The purpose is to launch a daemon process on a remote host via ssh.</p>
  
  <p><strong>test.sh</strong></p>
  
  <pre><code>#!/bin/bash
  
  (
  sleep 2 
  echo "done"
  ) &amp;
  </code></pre>
  
  <p>When I run the script on the console it returns immediately, with "done" appearing 2 seconds later.</p>
  
  <p>When I run the script as an ssh script, the ssh command . It appears to wait until all child processes have terminated until ssh exits.</p>
  
  <p><strong>ssh example</strong></p>
  
  <pre><code>$ ssh mike@127.0.0.1 /home/mike/test.sh
  (2 seconds)
  done
  </code></pre>
  
  <p><strong>standard terminal example</strong></p>
  
  <pre><code>$ ./test.sh
  $ 
  (2 seconds)
  done
  </code></pre>
  
  <p>How can I make ssh return when the parent/main process has terminated?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I'm aware of the <code>-f</code> option to ssh to run the process in the background . It leaves the ssh process and connection open on the source host. For my purposes this is unsuitable.</p>