Execute a command in parallel by ssh

From wikieduonline
Jump to navigation Jump to search

  1. Execute a command in parallel by ssh in MACHINE1 and MACHINE2 using parallel
parallel ssh {} 'COMMAND' ::: MACHINE1 MACHINE2[1]. See also pssh.
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:


if [ $# -eq 0 ]; then
    echo -e '\nUSAGE: $0 "machine1 machine2 machine3" "command"\n'
    exit 0

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



See also[edit]

  • 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
  • Advertising: