Alex Alex -4 years ago 152
Linux Question

Exiting ssh -tt session

I am executing a script on a remote ssh host as follows:

ssh -tt $USER@somehost 'bash -s' < ./myscript.sh


Notice the pseudo tty
-tt
switch.

My problem is that after the script has finished running the ssh session is not ending. Typing
exit
doesn't do anything either. How do I make it exit?

Answer Source

You are missing an exit statement.

I suspect the reason that the exit is necessary is becase when you force allocation of a pty, the pty is expecting the input to be a terminal... Reading EOF from a terminal doesn't mean 'there is never, ever any more data to come' the way it does for a pipe / file - it just means that there is 'currently no more input from the user' - hence the hang... it's waiting for further input.

This input script (myscript.sh) 'hangs':

echo "Hello World..."

This doesn't:

echo "Hello World..."
exit 0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download