I'm experiencing sporadic problems when trying to ssh to windows servers (running either freesshd or Win32-OpenSSH, same results). When trying to run non-interactive commands (from Debian Jessie with OpenSSH client), sometimes (but not always, and at different intervals) remote command will stop and require pressing ENTER to continue.
For example:
ssh -4 -T somehost "mysqldump --master-data --all-databases" > backup.sql &
on some windows machines it finishes ok (if the databases are small enough) but on bigger ones it will usually stop (either immediately, with backup.sql
remaining with size 0, or after some time, with backup.sql
having from few megabytes to few hundred megabytes) and then shell will inform me that ssh client process is waiting for input:
[1]+ Stopped ssh -4 -T somehost "cat mysqldump --master-data --all-databases" > backup.sql
if I bring it to fg
and press ENTER, it will continue working, even after I CTRL+Z and bg
it. Sometimes it will finish then, other times it will stop again after some time.
strace confirms the process is waiting for TTY input (on file descriptor 4, which is RW opened /dev/pts/2
or similar PTY of shell spawning the ssh client) and that it is why process has been stopped.
If I run ssh from script without associated TTY it will die (as there is nobody to press ENTER). If I provide -n
option to redirect stdin from /dev/null
, ssh will die immediately upon connection. That poses additional problem, as ssh connections which are not run from terminal (but for example from cron(8)/atd(8)) will fail immediately.
Only close question I've found is this one, but the provided workaround (forcing PTY use) is not really applicable to my case (programs in question modify their behaviour when PTY is detected, adding ANSI sequencing and word wrapping etc).
Needless to say, the same commands that connect to hundreds of Debian (and other GNU/Linux) systems running OpenSSHD servers experience no problems whatsoever (weather using -n
or not). Problems only ever arise when sshd server is running on microsoft windows.
Does anyone have ideas how to fix or work around the problem? I've tried naive approach of:
yes '' | ssh -4 -T somehost "mysqldump --master-data --all-databases" > backup.sql &
but it does not work well (while it fixes the ssh waiting for keyboard, it also randomly manages to insert newlines into output, which is unacceptable). Also related OpenSSH server on Windows refusing to work without STDIN even in noninteractive mode
0 Answers