我需要通过ssh在后台复制一个大文件(大约30 Gb).如果我这样做,并断开连接,它被复制得很好:
ssh server # cp /file1 /file2 & >/dev/null 2>/dev/null ; disown;
但如果我这样做:
ssh server 'cp /file1 /file2 & >/dev/null 2>/dev/null ; disown;'
它一直等到文件副本.为什么?
解决方法
尝试添加-f:
ssh -f server 'cp /file1 /file2 & >/dev/null 2>/dev/null ; disown;'
(经过测试并适合我.)
从man page:
-f Requests ssh to go to background just before command execution. This is useful if ssh is going to ask for passwords or passphrases,but the user wants it in the background. This implies -n. The recommended way to start X11 programs at a remote site is with something like ssh -f host xterm.