终止SSH会话通过bash脚本执行 [英] Terminating SSH session executed by bash script
问题描述
我有一个剧本,我可以在本地运行远程启动服务器:
I have a script I can run locally to remotely start a server:
#!/bin/bash
ssh user@host.com <<EOF
nohup /path/to/run.sh &
EOF
echo 'done'
nohup的运行后,它挂起。我必须击中CTRL-C退出脚本。
After running nohup, it hangs. I have to hit ctrl-c to exit the script.
我试着在这里文档的末尾添加一个明确的退出,使用SSH-t的说法。无论是作品。我如何立即做出这个脚本退出?
I've tried adding an explicit exit at the end of the here doc and using "-t" argument for ssh. Neither works. How do I make this script exit immediately?
编辑:客户端是OSX 10.6,服务器是Ubuntu的
The client is OSX 10.6, server is Ubuntu.
推荐答案
我认为问题是,nohup的,当你从SSH进来不能重定向输出,只重定向当它认为它连接到一个到的nohup.out终端,我必须将prevent的标准输入覆盖,即使有 -t
。
I think the problem is that nohup can't redirect output when you come in from ssh, it only redirects to nohup.out when it thinks its connected to a terminal, and I the stdin override you have will prevent that, even with -t
.
一个解决方法可能是自己重定向输出,那么SSH客户端可以断开 - 这不是等着流关闭。是这样的:
A workaround might be to redirect the output yourself, then the ssh client can disconnect - it's not waiting for the stream to close. Something like:
nohup /path/to/run.sh > run.log &
的(这在一个简单的测试连接从一个OS X客户端的Ubuntu的服务器为我工作。)的
这篇关于终止SSH会话通过bash脚本执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!