Run bash script with multiple arguments in parallel on multiple hosts [closed]
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...
Solution 1:
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.
Solution 2:
You can do that with GNU Parallel
cat hosts.txt | parallel ssh {} "'bash -s' < ./myscript.sh arg1 arg2 arg3"