-2

Actually I want to execute my below bash script simultaneously on multiple hosts,i tried pssh command for this:

pssh -h hosts.txt -i -I < myscript arg1 arg2 arg3 

but its not executing, so plz tell me the proper way to execute this...

pawan1491
  • 27
  • 5

2 Answers2

2

GNU Parallel has a special mode for this: --onall:

parallel --slf hosts.txt --onall myscript.sh ::: arg1 arg2 arg3

This will run on all machines:

myscript.sh arg1
myscript.sh arg2
myscript.sh arg3

If you do not want the arguments to change you can use --nonall:

parallel --slf hosts.txt --nonall myscript.sh arg1 arg2 arg3

which will run:

myscript.sh arg1 arg2 arg3

on all machines. Use -j to adjust how many machines you want to log into in parallel.

Ole Tange
  • 2,836
  • 5
  • 29
  • 45
1

You can do that with GNU Parallel

cat hosts.txt | parallel ssh {} "'bash -s' < ./myscript.sh arg1 arg2 arg3"

Anubioz
  • 3,597
  • 17
  • 23