title: ssh session will not close after running remote command
body: <p>i have seen similar questions on the web but none of the answers work, hoping a fresh request will reveal an answer.</p>
  
  <p>i am trying to run a remote query on a linux box which i can do the problem is i stay connected to the remote server.</p>
  
  <p>i have set -x in the script so i am watching the output.
  Part of my script is below</p>
  
  <pre><code>ssh -tt $host.digital.domain.com &lt;&lt; EOF
  sudo su - foo
  /apps/scripts/bar.sh
  exit
  EOF
  </code></pre>
  
  <p>the script is runs correctly</p>
  
  <pre><code>[user@server ~]$ [foo@host ~]$ + rm -f '/tmp/files*'
  </code></pre>
  
  <p>however the window then gives me the prompt on the remote computer instead of exiting.</p>
  
  <pre><code>[foo@host ~]$
  </code></pre>
  
  <p>i used the -tt switch as i was getting the tty error
  i have also tried to kill the pid but this doesnt work either.
  the only way to progress the script is for me to 'ctrl c' to exit the remote session.</p>
  
  <p>i have tried running ssh it all on one line however this didnt work, possibly due to the sudo, i'm not sure.</p>
  
  <p>Any advice would be great.</p>
  
  <p>thanks</p>