A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Parallel SSH
是 Python 写的可以在多台服务器上执行命令的工具,可以实现文件复制,可以批量管理多台服务器的一个小工具。
-bash/zsh: pssh: command not found # Windows (WSL2) sudo apt-get update sudo apt-get install pssh # Debian apt-get install pssh # Ubuntu apt-get install pssh # Alpine apk add pssh # Kali Linux apt-get install pssh # Fedora dnf install pssh # OS X brew install pssh # Raspbian apt-get install pssh # Dockerfile dockerfile.run/pssh # Docker docker run cmd.cat/pssh pssh
pssh 全称为 parallel-ssh,是一个用 Python 编写的可以并发在多台服务器上批量执行命令的工具。
提供了一系列命令如 pssh、pscp、prsync、pnuke 和 pslurp,支持远程并行执行命令、杀掉进程、复制文件等等,是十分方便的批量管理主机的命令。使用 pssh 相关命令时不需要在受控节点上安装任何类似 agent 的东西,只需要在管理节点上安装 pssh,然后让管理节点可以通过 ssh 登录受控节点即可。
在容器化大行其道的今天,对机器节点本身进行操作的需求在减少,但是 pssh 命令仍然有它适合的使用场景。
pss [ -fLkrSPv ] [ -s cell ] [ -R n ] [ -C n ] [ -n n ] [ -d c ]
Options: -f Omit column width calculations. This option is for preparing data to be merged with an existing spreadsheet. If the option is not specified, the column widths calculated for the data read by pss will override those already set in the existing spreadsheet. -L Left justify strings. -k Keep all delimiters. This option causes the output cell to change on each new delimiter encountered in the input stream. The default action is to condense multiple delimters to one, so that the cell only changes once per input data item. -r Output the data by row first then column. For input consisting of a single column, this option will result in output of one row with multiple columns instead of a single column spread sheet. -s cell Start the top left corner of the spread sheet in cell. For example, -s B33 will arrange the output data so that the spread sheet starts in column B, row 33. -R n Increment by n on each new output row. -C n Increment by n on each new output column. -n n Output n rows before advancing to the next column. This option is used when the input is arranged in a single column and the spread sheet is to have multiple columns, each of which is to be length n. -d c Use the single character c as the delimiter between input fields. -P Plain numbers only. A field is a number only when there is no imbeded [-+eE]. -S All numbers are strings. -v Print the version of pss
主机信息
pssh 在两台主机上运行命令,并在每台服务器上内联打印其输出:
pssh -i -H "host1 host2" hostname -i
pssh 在两台主机上运行命令,并在每台服务器上内联打印其输出:
pssh -H host1 -H host2 -o path/to/output_dir hostname -i