pssh用法范例

下载安装pssh

$ wget https://pypi.python.org/packages/60/9a/8035af3a7d3d1617ae2c7c174efa4f154e5bf9c24b36b623413b38be8e4a/pssh-2.3.1.tar.gz
$ tar xf pssh-2.3.1.tar.gz -C /usr/local
$ cd /usr/local/pssh-2.3.1/
$ python setup.py install
$ pssh --help
Usage: 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
                        hosts file (each line "[user@]host[:port]")
  -H HOST_STRING, --host=HOST_STRING
                        additional host entries ("[user@]host[:port]")
  -l USER, --user=USER  username (OPTIONAL)
  -p PAR, --par=PAR     max number of parallel threads (OPTIONAL)
  -o OUTDIR, --outdir=OUTDIR
                        output directory for stdout files (OPTIONAL)
  -e ERRDIR, --errdir=ERRDIR
                        output directory for stderr 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 for a password (OPTIONAL)
  -x ARGS, --extra-args=ARGS
                        Extra command-line arguments, with processing for
                        spaces, quotes, and backslashes
  -X ARG, --extra-arg=ARG
                        Extra command-line argument
  -i, --inline          inline aggregated output and error for each server
  --inline-stdout       inline standard output for each server
  -I, --send-input      read from standard input and send as input to ssh
  -P, --print           print output as we get it

Example: pssh -h hosts.txt -l irb2 -o /tmp/foo uptime

常用命令

#pssh 远程批量执行命令 
pssh -h ip.txt -P "uptime" 
#-h  后面接主机ip文件,文件数据格式[user@]host[:port]
#-P  显示输出内容
#如果没办法密钥认证.可以采用下面方法,但不是很安全
sshpass -p abcd-1234 pssh -A -h ip.txt -i "uptime"
 
#pscp 并行传输文件到远端
#传文件,不支持远程新建目录
pscp -h ip.txt test.py /tmp/dir1/
#传目录
pscp -r -h ip.txt test/ /tmp/dir1/
 
#prsync 并行传输文件到远端
#传文件,支持远程新建目录,即目录不存在则新建
prsync -h ip.txt test.py /tmp/dir2/
#传目录
prsync -r -h ip.txt test/ /tmp/dir3/
 
#pslurp从远程拉取文件到本地,在本地自动创建目录名为远程主机ip的目录,将拉取的文件放在对应主机IP目录下
#格式:pslurp -h ip.txt -L <本地目录>  <远程目录/文件>  <本地重命名>
#拉取文件
pslurp -h ip.txt -L /root/ /root/1.jpg picture
ll /root/172.16.1.13/picture
-rw-r--r-- 1 root root 148931 Jan  9 15:41 /root/172.16.1.13/picture
#拉取目录
pslurp -r -h ip.txt -L /root/ /root/test temp
ll -d /root/172.16.1.13/temp/
drwxr-xr-x 2 root root 23 Jan  9 15:49 /root/172.16.1.13/temp/
 
#pnuke:远程批量killall
pnuke -h ip.txt nginx
上一篇:(AIDE)Android Eclipse JNI 调用 .so文件加载问题


下一篇:Spring Boot整合JPA