I need to connect multiple computers to run different programs. For different computers, I need to send them different command. How to use ssh command to connect to multiple computers and send different commands to each computers? My command to run program for each computer isnohup Rscript program_i.R > program_i_out.txt. To be detailed. I want to use 3 computers to run 3 programs. Then, I will sendnohup Rscript program_1.R > program_1_out.txt to first computer,nohup Rscript program_2.R > program_2_out.txt to second computer,nohup Rscript program_3.R > program_3_out.txt to third computer.
how to use ssh command to connect to multiple computers and send different commands to each computers at same time
linux;ssh;terminal
Try ssh -f user@host '<your command here>'.From the ssh 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.For example, if i do ssh -f <my computer> 'echo hello $(pstree -p | grep sshd | wc -l) person in ssh!, it prints 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.Hope this helps!