Reputation: 9429
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?
Upvotes: 3
Views: 5788
Reputation: 6979
You are missing an exit
statement.
I suspect the reason that the exit
is necessary is because 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
Upvotes: 7
Reputation: 75575
In the absence of further information, the following script correctly exits after execution even when executed as in the question. If this does not work, please provide an example for which it does not work.
echo Hello World
pwd
exit
Upvotes: 2