Pssh, pscp, and pslurp usage

Source: Internet
Author: User
Tags pscp

Because it is often necessary to execute the same command on dozens of machines, cluster management tools such as saltstack or puppet are not deployed on the machines. since each server uses the same public key, some scripts were previously written: Put the IP address in a file, and then read an IP address from the file in sequence, log on to the target machine using SSH and execute the command. at first, I thought it was acceptable, at least less time and effort than manually logging on to each machine. however, we later found that SSH connections on some machines were slow and it would take a while to wait. As it was executed by a single process in order, we felt a little slow and wanted to be faster. later. after checking the pssh tool, I took the time to practice it. Below are some of my practices and usage experiences (I will not describe the installation method here ):

1. Use of pssh

Take a look at the instructions: Man pssh

Options-H host_file #-H + file name containing IP -- hosts host_file-H [[email protected] host [: port] #-H + <span style = "font-family: Arial, Helvetica, sans-serif;"> [user @] Host IP Address [: port] [] is an optional parameter. If multiple hosts exist, use, separate hosts by spaces </span> -- Host [[email protected] host [: Port]-h "[[email protected] host [: port] [[[email protected] host [: Port]...] "<span style =" white-space: pre "> </span> -- Host" [[email protected] host [: port] [[[email protected] host [: Port]...] "-l user #-L + User Name (user name used to connect to the remote host) -- User user-P parallelism #-P + concurrency -- par parallelism-T timeout #-T + timeout seconds -- timeout-O outdir #-O + output directory description: <span style = "font-family: Arial, Helvetica, sans-serif;"> [user @] Host IP Address [: port] </span> <span style = "font-family: Arial, Helvetica, sans-serif;"> Format File Name, used to save the output result </span> -- outdir-e errdir #-e + error output directory -- parameters that can be provided when the errdir-x ARGs #-x + SSH connection is established, example: -X "-O stricthostkeychecking = No" indicates to skip the SSH link and ask yes/no -- extra-ARGs-x ARG -- extra-Arg-O options #-O + SSH configuration. the options in the file can contain multiple-O options -- Options options-A -- askpass-I #-I parameters to display the output result directly on the current terminal -- inline-stdout-V # The-V parameter is used to display the error message -- verbose-I -- send-input read input and send to each SSH process during SSH connection. since SSH allows a command script to be sent on standard input, the-I option may be used in lieu of the command argument. the-P #-p parameter is used to output the execution result after the host is connected. The execution result is output first, and the connected host information is displayed. -- print

Pssh-H i2.txt "ifconfig"

If you have not previously connected to the target machine from the host where pssh is located, you must run the home parameter-X "-O stricthostkeychecking = No". If this parameter is not added:

Because xxxx.104 and xxx.70 have not been connected to the machine through SSH, the command execution fails, and sometimes the commands on the host fail to be executed, after the-X "-O stricthostkeychecking = No" parameter is added:

The above command only shows whether the execution is successful, but does not show the output result of the command, you need to add the-I parameter:

Specify the output directory-O parameter:

2. pscp is used to copy local files to a remote host.

Many parameters of pscp and pssh are the same.

-The R parameter is used to recursively copy directories.

Remote directory of local pscp-h ip File

3. pslurp is used to copy files on the remote host back to the local device.

The pslurp parameter is the same as the pscp parameter.

-L parameter is used to specify the directory for storing local files

Plurp-L-h ip address local name of the Remote File

Although the-l parameter is optional in the help document, after my experiment, I found that-l should be required or an error will be reported. The experiment results are as follows:

After the-l parameter is added, the [user @] Host IP Address [: Port] Directory will be created in the local directory specified by-L, the corresponding directory stores the files copied from the host.

4. pnuke is used to remotely terminate processes in batches.

The pnuke parameter is the same as that of Pssh, but the final string is the name of the process to end.

For example, pnuke-H i2.txt httpd indicates that the HTTPd process of all hosts in the i2.txt file is terminated.


The above is only a personal experiment and usage experience, used for memo, and hope to help some students!

Pssh, pscp, and pslurp usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.