(1)我可以运行以下命令并成功获取输出
ssh server hostname
(2)如果我在后台运行(不是后台hotname
,而是后台ssh
)
ssh server hostname &
除了等待,别无所求,我可以得到输出
(3)但是,如果在完成之前我在终端上键入了任何键,则作业将立即变为挂起状态
[ZSH] suspended (tty input) ssh server hostname
[BASH] Stopped ssh server hostname
这是什么原因以及如何解决?
我仅以hostname
为例。如果程序返回速度太快,则可以尝试使用sleep 5
。我要运行的实际程序持续了几分钟。
答案 0 :(得分:0)
使用ssh -T -f server hostname
作为手册页上的状态:
-f requests ssh to go to background just before command execution.
This is useful if ssh is going to ask for passwords or
passphrases, but the user wants it in the background. This
implies -n. The recommended way to start X11 programs at a
remote site is with something like ssh -f host xterm.
If the ExitOnForwardFailure configuration option is set to “yes”,
then a client started with -f will wait for all remote port for-
wards to be successfully established before placing itself in the
background.
-T Disable pseudo-tty allocation.