我有一些正在虚拟机上开发的脚本,但有时需要在生产服务器上运行才能进行正确测试。
我需要脚本的输出来进行调试,所以我整理了以下解决方案:
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 文件中了
我想使用
在后台运行它test_remote path_to_file/php_file.php &
但我总是得到以下结果
[1] + 12996 suspended (tty input) test_remote path_to_file/php_file.php
如果我用 bg 恢复它,它只会重复相同的消息
最佳答案
当后台进程试图从标准输入读取时,它会收到一个暂停它的信号。这样用户就可以再次将进程带到前台并提供必要的输入。
如果不需要提供输入,您可以在调用 test_remote
或 cmd
时从 /dev/null
重定向标准输入>.
关于shell - 在后台运行的 ssh 进程被暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34394237/