title: Bash script to set up a temporary SSH tunnel
body: <p>On Cygwin, I want a Bash script to:</p>
  
  <ol>
  <li>Create an SSH tunnel to a remote server. </li>
  <li>Do some work locally that uses the tunnel. </li>
  <li>Then shut down the tunnel.</li>
  </ol>
  
  <p>The shutdown part has me perplexed.</p>
  
  <p>Currently, I have a lame solution. In one shell I run the following to create a tunnel:</p>
  
  <pre><code># Create the tunnel - this works! It runs forever, until the shell is quit.
  ssh -nNT -L 50000:localhost:3306 jm@sampledomain.com
  </code></pre>
  
  <p>Then, in another shell window, I do my work:</p>
  
  <pre><code># Do some MySQL stuff over local port 50000 (which goes to remote port 3306)
  </code></pre>
  
  <p>Finally, when I am done, I close the first shell window to kill the tunnel.</p>
  
  <p>I'd like to do this all in one script like:</p>
  
  <pre><code># Create tunnel
  # Do work
  # Kill tunnel
  </code></pre>
  
  <p>How do I keep track of the tunnel process, so I know which one to kill?</p>