[英]Using ssh to execute a remote script in the background doesn't exit immediately
Why the follow ssh command doesn't exit immediately.为什么跟随 ssh 命令没有立即退出。 Instead, it will exit after 1m相反,它会在 1m 后退出
ssh -vvv <usr>@<ip> 'sh -c "sleep 60 &"'
But I do tell shell to run sleep command in the background, I don't know why但是我确实告诉 shell 在后台运行 sleep 命令,我不知道为什么
It's because the file descriptors opened by the sh
process are indirectly connected to your ssh session's tty.这是因为sh
进程打开的文件描述符间接连接到您的 ssh 会话的 tty。
sleep
command does not take anything on stdin
not does it send anything back to stdout/stderr
. sleep
命令不会在stdin
上接收任何内容,也不会将任何内容发送回stdout/stderr
。 However, the FDs inherited from sh
are still open.但是,从sh
继承的 FD 仍然是打开的。
The way out is to close those FDs by ip/op/err redirection.出路是通过 ip/op/err 重定向关闭那些 FD。
ssh -vvv <usr>@<ip> 'sh -c "sleep 60 &" &>/dev/null </dev/null'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.