Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Automation tool Parallel SSH under Linux

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use the automation tool Parallel SSH under Linux. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Parallel-ssh is an asynchronous parallel SSH library designed for small-scale automation, including pssh, pscp, prsync, pslurp and pnuke tools, whose source code is written and developed in the Python language. The project was originally located on Google Code and was written and maintained by Brent N.Chun, but due to the busy work, Brent handed over the maintenance work to Andrew McNabb management in October 2009. In 2012, due to the closure of Google Code, the project was once abandoned, and now the current version can only be found in Google Code archives.

However, it should be noted that the previous version does not support Python3, but there is a copy of Fork on Github, which has been modified to support versions above Python3. At the same time, there is another organization that has developed and maintained parallel-ssh, which has not been updated for a long time today. If you need it, you can check it yourself.

Lilydjwg/pssh-supported on Python 3.5 and later

ParallelSSH/parallel-ssh-asynchronous parallel SSH client library

Expandability

It can be extended to hundreds or even thousands of hosts.

Easy to use

You can run commands on any number of hosts with just two lines of code

Efficient execution

Claims to be the fastest Python SSH library available

Resource usage

Compared with other Python SSH libraries, it consumes the least resources.

# Mac system installation $brew install pssh# CentOS system installation $yum install pssh# Ubuntu system installation $apt install pssh# PIP installation $pip insall pssh# source code compilation installation (2.3.1) # official address: https://code.google.com/archive/p/parallel-ssh/source/default/source $tar zxvf pssh-2.3.1.tar.gz $cd pssh-2.3.1$ python setup.py install

The version of ParallelSSH above Google

# tool corresponding subcommand $ls-lh / usr/local/Cellar/pssh/2.3.1_1/bin/ pnuke->.. / libexec/bin/pnuke prsync->.. / libexec/bin/prsync pscp->.. / libexec/bin/pscp pslurp->.. / libexec/bin/pslurp pssh- >.. / libexec/bin/pssh pssh-askpass->.. / libexec/bin/pssh-askpass numbering subcommand explains 1pssh corresponding to the function Run commands in parallel on multiple hosts through the ssh protocol 2pscp copies files to multiple hosts in parallel through the ssh protocol 3rsync copies files to multiple hosts in parallel over the rsync protocol 4slurp copies files from multiple remote hosts to the central host in parallel through the ssh protocol 5pnuke kills process 1. Pssh on multiple remote hosts in parallel through the ssh protocol

Run commands in parallel on multiple hosts through the ssh protocol

Command parameters use

The numbering parameter option corresponds to the parameter explanation 1murh HOST_FILE specifies the host file list file; the content format is "[user@] host [: port]" 2murH HOST_STRING specifies the host string address The content format is "[user@] host [: port]" 3Mul USER specifies the username 4-p PAR to be used for login to set the number of concurrent threads (optional) 5muro OUTDIR standard normal output file directory (optional) 6mure ERRDIR standard error output file directory (optional) 7murt TIMEOUT timeout setting Where 0 means unlimited (optional) 8Mel O OPTION set SSH option 9Mel x ARGS extra command line arguments use blank symbols, quotes, backslashes to handle 10 Muz X ARG extra command line arguments, single parameter mode, same as-x parameter 11Mui A manual input password mode 12MUTI each server internal processing information output 13Muth P prints out server return information 14--help view help That is, this information 15--version displays the program version number

Applicable example

# Usage: pssh [OPTIONS] command [...] # run commands on two hosts and print their output $pssh-I-H "host1 host2" hostname-I # run commands and save the output to a separate file $pssh-H host1-H host2-o path/to/output_dir hostname-I # run commands on multiple hosts and specify in new line-delimited files $pssh-I-h path/to/hosts_file hostname-I # runs the command in root (requires a root user password) $pssh-I-h path/to/hosts_file-A-l root_username hostname-I # runs the command with additional SSH parameters $pssh-I-h path/to/hosts_file-x "- O VisualHostKey=yes" hostname-I # runs the command with a limit of 10 parallel connections $pssh -I-h path/to/hosts_file-p 10'cd dir . / script.sh; exit'2. Pscp

Copy files to multiple hosts in parallel through ssh protocol

Command parameters use

The numbering parameter option corresponds to the parameter explanation 1murh HOST_FILE specifies the host file list file; the content format is "[user@] host [: port]" 2murH HOST_STRING specifies the host string address The content format is "[user@] host [: port]" 3Mul USER specifies the username 4-p PAR to be used for login to set the number of concurrent threads (optional) 5muro OUTDIR standard normal output file directory (optional) 6mure ERRDIR standard error output file directory (optional) 7murt TIMEOUT timeout setting Where 0 denotes unlimited (optional) 8muro OPTION set SSH option 9Murx ARGS extra command line arguments use blank symbols, quotes, backslashes to deal with 10murx ARG additional command line arguments, single parameter mode, same as-x parameter 11MUA manually enter password mode 12MUR for recursive copy directory (optional) 13--help view help, that is, this information 14--version displays the program version number

Applicable example

# Usage: pscp [OPTIONS] local remote # copy local files to a remote machine $pscp-h hosts.txt-l root foo.txt / home/irb2/foo.txt [1] 23:00:08 [SUCCESS] 172.18.10.25 [2] 09:52:28 [SUCCESS] 172.18.10.243. Prsync

Efficiently copy files to multiple hosts in parallel through rsync protocol

Command parameters use

The numbering parameter option corresponds to the parameter explanation 1murh HOST_FILE specifies the host file list file; the content format is "[user@] host [: port]" 2murH HOST_STRING specifies the host string address The content format is "[user@] host [: port]" 3Mul USER specifies the username 4-p PAR to be used for login to set the number of concurrent threads (optional) 5muro OUTDIR standard normal output file directory (optional) 6mure ERRDIR standard error output file directory (optional) 7murt TIMEOUT timeout setting Where 0 means unlimited (optional) 8muro OPTION set SSH option 9Murx ARGS extra command line arguments use blank symbols, quotes, backslashes to handle 10murx ARG additional command line arguments, single argument mode Same as-x parameter 11Musa manually enter password mode 12murr for recursive replication directory (optional) 12mura uses rsync archiving mode (optional) 12Muz uses rsync compression mode (optional 12murs ARGS sets extension parameters of ssh protocol (optional) 13--help view help, that is, this information 14--version displays the program version number

Applicable example

# Usage: prsync [OPTIONS] local remote # uses the rsync protocol to copy local files $prsync-r-h hosts.txt-l root foo / home/irb2/foo4. Pslurp

Copy files from multiple remote hosts to the central host in parallel through the ssh protocol

Command parameters use

The numbering parameter option corresponds to the parameter explanation 1murh HOST_FILE specifies the host file list file; the content format is "[user@] host [: port]" 2murH HOST_STRING specifies the host string address The content format is "[user@] host [: port]" 3Mul USER specifies the username 4-p PAR to be used for login to set the number of concurrent threads (optional) 5muro OUTDIR standard normal output file directory (optional) 6mure ERRDIR standard error output file directory (optional) 7murt TIMEOUT timeout setting Where 0 means unlimited (optional) 8Mel O OPTION set SSH option 9Mel x ARGS extra command line arguments use blank symbols, quotes, backslashes to handle 10murx ARG extra command line arguments, single parameter mode, same as-x parameter 11MUA manually enter password mode 12MUR for recursive copy directory (optional) 13Mel LOCALDIR specifies the directory where files are stored locally 14--help view help That is, this information 15--version displays the program version number

Applicable example

# Usage: pslurp [OPTIONS] remote local # copy the files on the remote host to the local $pslurp-h hosts.txt-l root-L / tmp/outdir / home/irb2/foo.txt foo.txt5. Pnuke

Kill processes on multiple remote hosts in parallel through the ssh protocol

Command parameters use

The numbering parameter option corresponds to the parameter explanation 1murh HOST_FILE specifies the host file list file; the content format is "[user@] host [: port]" 2murH HOST_STRING specifies the host string address The content format is "[user@] host [: port]" 3Mul USER specifies the username 4-p PAR to be used for login to set the number of concurrent threads (optional) 5muro OUTDIR standard normal output file directory (optional) 6mure ERRDIR standard error output file directory (optional) 7murt TIMEOUT timeout setting Where 0 means unlimited (optional) 8Mel O OPTION set SSH option 9Mel x ARGS extra command line arguments use blank symbols, quotes, backslashes to deal with 10murx ARG extra command line arguments, single parameter mode, same as-x parameter 11Mui A manually enter password mode 12--help to view help, that is, this information 13--version displays the program version number

Applicable example

# Usage: pnuke [OPTIONS] pattern # end the process task on the remote host $pnuke-h hosts.txt-l root java so much about how to use the automation tool Parallel SSH under Linux. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report