我需要连接多台计算机才能运行不同的程序。对于不同的计算机,我需要向他们发送不同的命令。如何使用ssh命令连接到多台计算机并向每台计算机发送不同的命令?我为每台计算机运行程序的命令是nohup Rscript program_i.R > program_i_out.txt
。待详细说明。我想使用3台计算机来运行3个程序。然后,我将发送
nohup Rscript program_1.R > program_1_out.txt
到第一台计算机,
nohup Rscript program_2.R > program_2_out.txt
到第二台计算机,
nohup Rscript program_3.R > program_3_out.txt
到第三台计算机。
尝试一下ssh -f user@host '<your command here>'
。
在ssh手册页中:
-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.
例如,如果我这样做ssh -f <my computer> 'echo "hello $(pstree -p | grep sshd | wc -l) person in ssh!"
,它将打印出来hello 1 person in ssh!
。
After it prints 2 the session automatically exits, but you do not have to wait for it to exit. If I do ssh -f <my computer> 'sleep 30 && echo "hello $(pstree -p | grep sshd | wc -l) person in ssh!"'
it appears as if nothing has happened and I can do anything as normal, but 30 seconds later, it prints hello 1 person in ssh!
.
Using the >
redirect will redirect all stdout to a file, but all errors will still be printed to your screen. To avoid this, you can use &>
to redirect all output, stdout and stderr, to a file.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句