I have function as such:
function accountSetup() {
ssh -tt $HOST << EOF
adduser billy
[second command]
[third command]
EOF
}
Which leaves the terminal hanging. I have had success using the -tt
flag previously to execute a few commands with EOF
interactively, but I can't seem to create a new account interactively on my remote server with the above script.
This works fine, allowing me to set a password, name, etc. :
function accountSetup() {
ssh -tt $HOST adduser billy
}
BUT, when I introduce my other necessary commands it starts getting dumb.. I'm sure there is a better way to execute them without repeatedly logging in like this:
function accountSetup() {
ssh -tt $HOST adduser billy
ssh -tt $HOST [third command]
ssh -tt $HOST [second command]
}
The Question: What is causing my terminal to hang in my first function? How can I ssh in once to create an account interactively and continue to execute commands?
Thanks :)
If you tell ssh
to take its input from a heredoc, it cannot simultaneously take input from you via tty.
You can rewrite your commands as:
function accountSetup() {
ssh -t $HOST '
adduser billy
[second command]
[third command]
'
}