Execute a command in parallel by ssh
Jump to navigation
Jump to search
↑ https://unix.stackexchange.com/questions/428997/on-which-host-does-this-parallel-command-hang
↑ https://unix.stackexchange.com/questions/428997/on-which-host-does-this-parallel-command-hang
- Execute a command in parallel by ssh in MACHINE1 and MACHINE2 using parallel
parallel ssh {} 'COMMAND' ::: MACHINE1 MACHINE2
[1]. See alsopssh
.parallel -q ssh {} 'ECHO "TEST"; COMMAND' ::: MACHINE1 MACHINE2
[2]-q
quote command. The command must be a simple command (see man bash) without redirections and without variable assignments. This will quote the command line and arguments so special characters are not interpreted by the shell.
Using variables:
parallel -q ssh {} "echo {}; $COMMAND" ::: $MACHINES
or creating a basic shell script:
#!/bin/bash MACHINES="$1" COMMAND="$2" if [ $# -eq 0 ]; then echo -e '\nUSAGE: $0 "machine1 machine2 machine3" "command"\n' exit 0 fi parallel --keep-order -q ssh {} "echo {}; $COMMAND" ::: $MACHINES
You can have a similar solution with a for
loop but in this case command output will be mixed between both commands.
for HOST in HOSTNAME1 HOSTNAME2; do ssh $HOST "COMMAND" & done
Related[edit]
pssh
See also[edit]
- Ansible
parallel
,for
,xargs
,parallel --citation, sshlogin
xargs
,parallel
,paste
,map
- SSH clients:
ssh (OpenSSH)
,putty
, MobaXterm,plink
,mosh
,paramiko
,conch
pssh
,sshpass
andautossh
,sftp, Termius
Advertising: