Table of Contents
SSH - Parallel SSH
Preface
In general it is possible to say that in case that you’ll need to run a remote command on several SSH Servers Parallel SSH is the right application that can help you. In fact you write a script that will take list of your servers and run this command on all this server. On another hand you use Parallel SSH application and save your time.
Install Parallel SSH
Go to “ http://code.google.com/p/parallel-ssh/ ” and download last release
[root@SSH_Client pssh]# wget http://parallel-ssh.googlecode.com/files/pssh-2.3.1.tar.gz [root@SSH_Client pssh]# tar -vxzf pssh-2.3.1.tar.gz [root@SSH_Client pssh]# cp -r ./pssh-2.3.1 /opt/
I just like the old UX way to install applications in to “ /opt/ ” according to this I have moved the whole Parallel SSH in to “/opt/pssh-2.3.1”. According to this all Parallel SSH scripts are located in “ /opt/pssh-2.3.1/bin ”
[root@SSH_Client ~]# ls /opt/pssh-2.3.1/bin/ pnuke prsync pscp pslurp pssh pssh-askpass
Use Parallel SSH
List of SSH Servers
Description: “ host[:port] [user] ”
To use Parallel SSH we need to create a list of SSH Servers. It is possible to create several list of servers. According to this it is possible to group servers based for example on Linux/UX version. For example in the case that you would like to get the information about file system utilization you need to run “ df “ command on Linux servers and “ bdf “ command on HP-UX servers. According to this it is really handy to split list of servers to more as one configuration file to run right command on right server.
[user@SSH_Client ~]$ cat destinatio_servers.list SSH_Server1:22 user SSH_Server2:22 user [user@SSH_Client ~]#
Available commands
pssh | Start's command on all remote SSH Servers |
prsync | Synchronize file on list of SSH Servers |
pnuke | Kill process on list of SSH Servers |
pscp | Copy file to list of remote SSH servers |
pslurp | Copy file from list of SSH Servers |
Example (pssh)
[user@SSH_Client ~]$ /opt/pssh-2.3.1/bin/pssh -A -h ./destinatio_servers.list -o /tmp/result "uname -a" # Run command on list of SSH Server Warning: do not enter your password if anyone else has superuser privileges or access to your account. Password: # -A will ask you for password [1] 18:36:38 [SUCCESS] user@SSH_Server1:22 [2] 18:36:38 [SUCCESS] user@SSH_Server2:22 [user@SSH_Client ~]$ cd /tmp/result # -o = output directory [user@SSH_Client result]$ ls user@SSH_Server1:22 user@SSH_Server2:22 # list of files with command result [User@SSH_Client result]$ cat /tmp/result/* # Command results Linux SSH_Server1 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux Linux SSH_Server2 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Example (pscp)
[user@SSH_Client ~]$ /opt/pssh-2.3.1/bin/pscp -A -h ./destinatio_servers.list source_file /tmp/destination # Copy from SSH Client to SSH Servers Warning: do not enter your password if anyone else has superuser privileges or access to your account. Password: # -A will ask you for password [1] 19:05:35 [SUCCESS] user@SSH_Server1:22 [2] 19:05:35 [SUCCESS] user@SSH_Server2:22
Example (pslurp)
[user@SSH_Client ~]$ /opt/pssh-2.3.1/bin/pslurp -A -h ./destinatio_servers.list -L /tmp/result/ ~/.ssh/known_hosts downloaded.file Warning: do not enter your password if anyone else has superuser privileges or access to your account. Password: [1] 19:12:43 [SUCCESS] user@SSH_Server1:22 [2] 19:12:43 [SUCCESS] user@SSH_Server2:22 [user@SSH_Client ~]$ ll -R /tmp/result/ /tmp/result/: total 8 drwxr-xr-x. 2 user user 4096 Feb 3 19:12 SSH_Server1 drwxr-xr-x. 2 user user 4096 Feb 3 19:12 SSH_Server2 /tmp/result/SSH_Server1: total 4 -rw-r--r--. 1 user user 1182 Feb 3 19:12 downloaded.file /tmp/result/SSH_Server2: total 4 -rw-r--r--. 1 user user 393 Feb 3 19:12 downloaded.file