Lightweight automatic operation and maintenance tools


It is a python based tool that can execute commands on multiple servers or copy files. It provides multiple parallel tools based on ssh and scp

Usage: pscp.pssh [OPTIONS] local remote

Common options:

--Version: View version
 -h: host file list, content format "[user@]host[:port]"
-H: host string, content format "[user@]host[:port]"
-A: manual password mode
 -i: internal processing information output of each server
 -l: user name for login
 -p: number of concurrent threads [optional]
-o: output directory of standard output file (optional)
-e: output directory of standard error file (optional)
-t: TIMEOUT setting, 0 unlimited [optional]
-O: options for SSH
 -P: print out the server return information
 -v: detailed mode

[example 1] execute echo "hello pssh" in batch to the host in the host file list through pssh.

[root@CentOS7 ~]# cat host.txt

[root@CentOS7 ~]# pssh -h host.txt -i echo "hello pssh"
[1] 16:31:10 [SUCCESS]
hello pssh
[2] 16:31:10 [SUCCESS]
hello pssh
Note: when ssh key authentication is not supported, you can manually enter password authentication batch execution instructions through the - A option.

[example 2] save both standard error and standard correct redirection to the / app directory of the local host.

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

pscp.pssh command

Function: bulk copy local files to remote host

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

Option: basically the same as pssh command, but there is a - r option to copy directories recursively

[example 1] batch copy the local / etc/fstab file to the / app directory of the host in the host list file

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

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

[example 2] batch copy the local directory / test / to the host's / app directory in the host file list

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

[root@CentOS7 ~]# pssh -h host.txt -i ls /app/ -l
[1] 17:26:33 [SUCCESS]
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]
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: copy the files of the remote host to the local in batches, which is the opposite of the pscp.pssh command.

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(Local name)


-L copy the file from the remote host to the given local directory. Local is the name after downloading to the local

[example] batch download the passwd file of the target server to the local directory / app, and rename it user

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

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

2 directories, 2 files

Tags: Linux ssh Python Google

Posted on Sun, 10 Nov 2019 05:34:25 -0800 by hernan