Parallel ssh

Linux

Parallel ssh allows to execute commands on multiple hosts at the same time.

PSSH provides parallel versions of OpenSSH and related tools including:

pssh – run ssh in parallel on multiple remote hosts.

pscp – copy files in parallel to a number of hosts.

prsync –copy files in parallel to a number of hosts using the popular rsync.

pnuke – kills processes on multiple remote hosts in parallel.

pslurp – copy files in parallel from multiple remote hosts to a central host.

Pssh is written in python, so if python-pip is installed, simply run :

    sudo pip install pssh
How to use the pssh tools:

When connecting to remote hosts, the best and secure way is with ssh keys, but you have the ability to use a username/password.

To use a different username, we can use the -l switch and to make it ask for a password we can use the -A switch.

The host list:

The pssh tools are used with a list of hosts.

The hosts file contains one host name per line along with the IP address and port number that we need to connect to remote systems

=====================================================================

#######################

#example

#######################

192.168.0.101:22

#192.168.0.102 #ip-of-this-one-is-skipped it is a comment as in standard bash

192.168.0.125:1700

========================================================================

Using pssh:

pssh -O StrictHostKeyChecking=no -h -t -o “cat /etc/fstab”

-O StrictHostKeyChecking=no with the -O switch,we pass options of ssh to pssh. Here the host key checking is disabled.

This will disable the message about "authenticity of host can’t be established"._

ECDSA key fingerprint is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.

Are you sure you want to continue connecting (yes/no)?

-h host file above

-t a timeout for ssh.

-o The output for each host and each command will be written to a file in directory that will be created.

Using pscp (copy files to multiple hosts)
pscp -O StrictHostKeyChecking=no -h <hosts-file> -t <timeout> ~/localfile  /tmp/remotefile
Using pslurp (copy files from multiple remote hosts)
pslurp -O StrictHostKeyChecking=no -h <hosts-file> -t <timeout>  /tmp/remotefile ~/localfile
Using pnuke (kill processes on multiple remote hosts )
pnuke -O StrictHostKeyChecking=no -h <hosts-file> -t 10 php-fpm
Using prsync (copy files in parallel and sync them using rsync).
 prsync -O StrictHostKeyChecking=no -h hosts-file -t 10 -a   /home/sc/folder-to-send/ /tmp/folder-receive

Previous Post Next Post