在后台运行 ssh 进程被暂停 [英] running ssh process in background gets paused
问题描述
我有一些脚本正在虚拟机上开发,但有时需要在生产服务器上运行才能进行正确测试.
I have some scripts that I'm developing on a vm but sometimes needs to run on a production server to be properly tested.
我需要脚本的输出进行调试,所以我想出了以下解决方案:
I need the output from the scripts for debugging so I've tinkered together the following solution:
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"
}
我已经放在我的 .zshrc 文件中
which I have placed in my .zshrc file
我想使用
test_remote path_to_file/php_file.php &
但我总是得到以下结果
[1] + 12996 suspended (tty input) test_remote path_to_file/php_file.php
如果我用 bg 恢复它,它只会重复相同的消息
if I resume it with bg it just repeats the same message
推荐答案
当后台进程尝试从标准输入读取时,它会收到一个暂停它的信号.这样用户就可以再次将进程带到前台并提供必要的输入.
When a background process attempts to read from standard input, it is sent a signal which suspends it. This is so the user can bring the process to the foreground again and provide the necessary input.
如果不需要提供输入,您可以在调用 test_remote
或 cmd
时从 /dev/null
重定向标准输入>.
If no input needs to be provided, you can redirect the standard input from /dev/null
, either when calling test_remote
or in cmd
.
这篇关于在后台运行 ssh 进程被暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!