Lightweight automated operation and maintenance tool

pssh

Based on written python, the tool can execute commands on multiple servers, file replication can be achieved, providing a tool based on multiple concurrent ssh and scp the
project: http://code.google.com/p/parallel-ssh/
grammar:

Usage: pscp.pssh [OPTIONS] local remote

Common options:

--version:查看版本
-h:主机文件列表,内容格式”[user@]host[:port]”
-H:主机字符串,内容格式”[user@]host[:port]”
-A:手动输入密码模式
-i:每个服务器内部处理信息输出
-l:登录使用的用户名
-p:并发的线程数【可选】
-o:标准输出文件的输出目录(可选)
-e:标准错误文件的输出目录(可选)
-t:TIMEOUT 超时时间设置,0无限制【可选】
-O:SSH的选项
-P:打印出服务器返回信息
-v:详细模式

[Example 1] execute echo "hello pssh" to the list of hosts file hosts by pssh batch.

[root@CentOS7 ~]# cat host.txt 
172.20.200.200
192.168.8.61

[root@CentOS7 ~]# pssh -h host.txt -i echo "hello pssh"
[1] 16:31:10 [SUCCESS] 192.168.8.61
hello pssh
[2] 16:31:10 [SUCCESS] 172.20.200.200
hello pssh
NOTE: When the key authentication is not supported in ssh, by -A option to manually enter the password authentication batch execution instruction.

[Example 2] The standard error are saved and redirected to the correct standard under / app directory on the local host.

[root@CentOS7 ~]# pssh -h host.txt  -o /app/ -e /app/ -i echo "hello pssh"
[1] 16:52:32 [SUCCESS] 192.168.8.61
hello pssh
[2] 16:52:32 [SUCCESS] 172.20.200.200
hello pssh
[root@CentOS7 ~]# ls /app/
172.20.200.200  192.168.8.61
[root@CentOS7 ~]# cat /app/192.168.8.61 
hello pssh

pscp.pssh command

Function: bulk copy local files to the remote host
Syntax:

[root@CentOS7 ~]# pscp.pssh --help
Usage: pscp.pssh [OPTIONS] local remote

Options: consistent with pssh command, but there is a -r option to recursively copy directory

[Example 1] The local / etc / fstab file batch copied to the host host list file in the / app directory under

[root@CentOS7 ~]# pscp.pssh -h host.txt /etc/fstab /app/
[1] 17:19:32 [SUCCESS] 192.168.8.61
[2] 17:19:32 [SUCCESS] 172.20.200.200

[root@CentOS7 ~]# pssh -h host.txt -i ls /app/ -l
[1] 17:25:14 [SUCCESS] 192.168.8.61
total 4
-rw-r--r-- 1 root root 595 Nov  8 20:27 fstab
[2] 17:25:14 [SUCCESS] 172.20.200.200
total 4
-rw-r--r-- 1 root root 595 Nov  9 17:19 fstab

[Example 2] to copy the local directory / test / batch file to the host list of hosts in the / app directory

[root@CentOS7 ~]# pscp.pssh -h host.txt -r /test/ /app/
[1] 17:23:14 [SUCCESS] 192.168.8.61
[2] 17:23:14 [SUCCESS] 172.20.200.200

[root@CentOS7 ~]# pssh -h host.txt -i ls /app/ -l
[1] 17:26:33 [SUCCESS] 192.168.8.61
total 8
-rw-r--r-- 1 root root  595 Nov  8 20:27 fstab
drwxr-xr-x 2 root root 4096 Nov  8 20:33 test
[2] 17:26:33 [SUCCESS] 172.20.200.200
total 4
-rw-r--r-- 1 root root 595 Nov  9 17:19 fstab
drwxr-xr-x 2 root root  48 Nov  9 17:25 test

pslurp command

Function: The remote host batch files copied to the local, and pscp.pssh command opposite function.
grammar:

pslurp  [-vAr]  [-h hosts_file] [-H [user@]host[:port]] [-l user] [-p par] [-o outdir] [-e errdir] [-t timeout]  [-O  options]  [-xargs] [-X arg] [-L localdir] remote local(本地名)

Options:

-L 将文件从远程主机复制到给定的本地目录,local是下载到本地后的名称

[Example] batch download passwd file to the target server's local directory / app, and renamed user

[root@CentOS7 ~]# pslurp -h host.txt -L /app/ /etc/passwd user
[1] 17:35:38 [SUCCESS] 192.168.8.61
[2] 17:35:38 [SUCCESS] 172.20.200.200

[root@CentOS7 ~]# tree /app/
/app/
├── 172.20.200.200
│   └── user
└── 192.168.8.61
    └── user

2 directories, 2 files

Guess you like

Origin blog.51cto.com/hexiaoshuai/2449270