The Pssh command is a python-written tool that can execute commands on multiple servers while supporting the copying of files, which is excellent in the same kind of tool, similar to PDSH, which individuals consider to be relatively pdsh easier to use and must be configured with key authentication access on each server.
1. Installation
Installation can use Yum or Apt-get installation, you can also use the source code installation, because I use Apt-get installation is not good, so here I only say the source installation
wget http://tar XF pssh-2.3. 1. Tar . GZ CD pssh-2.3. 1/Install
2. Pssh option Description
------------- ---X: Additional command line arguments, single parameter mode, same---P: Print out server return information
3. Example
(1) View version
#pssh--version#2.3. 1
(2) View Help
#pssh--helpusage:pssh [OPTIONS] command [...] Options:--version Show Program'S version number and exit--Help show this help message and exit-H Host_file,--hosts=Host_file hostsfile(Each line"[email protected]]host[:p ORT]") -H host_string,--host=host_string additional HOST entries ("[email protected]]host[:p ORT]") -L USER,--user=USER username (OPTIONAL)-P PAR,--par=PAR max number of parallel threads (OPTIONAL)-O OUTDIR,--outdir=OUTDIR Output Directory forstdout Files (OPTIONAL)-E Errdir,--errdir=errdir Output Directory forstderr files (OPTIONAL)-T TIMEOUT,--timeout=Timeout Timeout (secs) (0=no timeout) per host (OPTIONAL)-O OPTION,--option=option SSH option (OPTIONAL)-V,--verbose turn on warning and diagnostic messages (OPTIONAL)-A,--askpass Ask fora password (OPTIONAL)-X ARGS,--extra-args=ARGS Extra Command-line arguments, with processing forspaces, quotes, and backslashes-X ARG,--extra-arg=ARG Extra Command-Line Argument-I,--inline inline aggregated output and error forEach server--inline-stdout Inline Standard Output forEach server-I,--send-input read from standard input and send as input toSSH-P,--Print Print output as we get itexample:pssh-H hosts.txt-l irb2-o/tmp/fooUptime
(3) Use the Host file list to perform the pwd command
#pssh-H ip.txt-a-I.pwdWarning: DoNot enter your passwordifAnyoneElseHave superuserprivileges or access to your account. Password: [1] +: -:Wuyi[SUCCESS] [Email protected]192.168.200.152/root[2] +: -:Wuyi[SUCCESS] [Email protected]192.168.200.154/root[3] +: -:Wuyi[SUCCESS] [Email protected]192.168.200.153/root[4] +: -: the[SUCCESS] [Email protected]192.168.200.155/root
Description: The IP after-h is the list of machine IPs to be operated in the following format: [email protected]-A means manually entering the password mode-I indicates the command to execute
(4) Using the Host file list to execute the date command
#pssh-H ip.txt-a-I.DateWarning: DoNot enter your passwordifAnyoneElseHave superuserprivileges or access to your account. Password: [1] -: -: $[SUCCESS] [Email protected]192.168.200.152Monday, July 11, 2016 -:Ten: -cst[2] -: -: $[SUCCESS] [Email protected]192.168.200.154Monday, July 11, 2016 -:Ten: Onecst[3] -: -: $[SUCCESS] [Email protected]192.168.200.153Monday, July 11, 2016 -:Ten: Aboutcst[4] -: -: $[SUCCESS] [Email protected]192.168.200.155Monday, July 11, 2016 -:Ten:TenCst
Through the above we can see directly can execute the command remotely, for the machine's bulk operation is very convenient. When you use it, you can write the script according to your actual needs.
Here are just a few examples to write about.
Linux Command Learning 5-pssh command