Pssh, pscp, pslurp usage practices, psshpscp

Source: Internet
Author: User
Tags pscp

Pssh, pscp, pslurp usage practices, psshpscp

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 [user @] host [: port] #-H + <span style = "font-family: arial, Helvetica, sans-serif; "> in [user @] Host IP Address [: Port] [], this parameter is optional. If there are multiple hosts, it is caused, separate hosts by spaces </span> -- host [user @] host [: port]-H "[user @] host [: port] [[user @] host [: port]...] "<span style =" white-space: pre "> </span> -- host" [user @] host [: port] [[user @] host [: port]...] "-l user #-l + user Name (user name used to connect to the remote host) -- 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-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!




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.