在后台运行的 ssh 进程被暂停

use*_*470 5 ssh shell terminal zsh

我有一些正在虚拟机上开发的脚本,但有时需要在生产服务器上运行才能进行正确测试。

我需要脚本的输出进行调试,因此我修补了以下解决方案:

function test_remote() {
    scp $1 Prod:/home/xxx/tmp/
    n=${1:t:r}
    f=${1:t}
    cmd="ssh Prod \"/usr/bin/php /home/xxx/tmp/$f\" > /home/xxx/tests/$n-remote-test.html"
    eval ${cmd}
    ssh Prod "rm /home/xxx/tmp/$f"
    echo "done"
}
Run Code Online (Sandbox Code Playgroud)

我已将其放入 .zshrc 文件中

我想使用在后台运行它

test_remote path_to_file/php_file.php &
Run Code Online (Sandbox Code Playgroud)

但正如我所做的那样,我总是得到以下结果

[1]  + 12996 suspended (tty input)  test_remote path_to_file/php_file.php
Run Code Online (Sandbox Code Playgroud)

如果我用 bg 恢复它,它只会重复相同的消息

Jen*_*ens 3

当后台进程尝试从标准输入读取数据时,系统会向其发送一个信号,将其挂起。这样用户就可以再次将进程带到前台并提供必要的输入。

如果不需要提供输入,您可以/dev/null在调用时test_remote或在 中重定向标准输入cmd