Ssh – How to issue parallel commands to remote nodes with different arguments

parallelismpdshssh

I need to execute an application in parallel on multiple Ubuntu servers while supplying different arguments for different servers. I tried to google it, but could not get to the possible solution. I even experimented with ssh/pdsh/parallel, but without success.

To explain the scenario further, here is a non-working example (with pdsh) where script.sh should be executed on all 3 servers in parallel but with different arguments. FYI, I already have public/private ssh-key (password-free login) in place.

pdsh -w server1,server2,server3 -l username script.sh args

Where args should be 1 for server1, 2 for server2 etc.

I would appreciate if someone can help me achieve this, either using pdsh or some other tool available in Ubuntu.

Best Answer

You can use GNU version of parallel

For example, to call echo with the arguments 1 through 10, dispatching each echo command to one of server.example.com or server2.example.net:

seq 10 | parallel --sshlogin server.example.com,server2.example.net echo
Related Question