I'm running a command like this:

ssh -tt server "/bin/bash -c \"trap 'kill -HUP 0' EXIT && awk '{print; exit}' > test.txt && ./test.sh\"" <<< "TEST"

This SSH command connects to a server, sends some data over STDIN, reads the first line, and uses that to run a command. It also sets up an EXIT signal handler that kills the process group on exit, which requires a pseudo-terminal (-tt) otherwise the handler doesn't seem to run. Reading an exact number of lines of STDIN and explicitly exiting is required because, when using a pseudo-tty, STDIN is never closed so something like cat > or head -1 > will hang.

All of this works perfectly, except STDIN will always be echoed to the terminal running the command, resulting in the following output:

$ ssh ... <<< "TEST"
Connection to server closed.

In my real script, I'm sending over a significant amount of data on STDIN, which causes anywhere from 10 to 100 rows of base64 nonsense to be echoed to the terminal.

Is there any way to suppress that output? I'm not even sure what's causing the echo, setting stty -echo and ssh -q had no effect.

  • Why do you need that monstrosity in the first place? What are trying to do exactly? I don't understand why you need a pseudoterminal or create a file on the server just to run some non-interactive shell commands. FWIW, stty -echo works if you manage to run it before the TEST is echoed back. You can achieve that with some timeout kludge. But better re-think your approach. – user414777 Sep 21 '20 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.