Lightweight automatic operation and maintenance tools

pssh

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
Item: http://code.google.com/p/parallel-ssh/
Syntax:

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 
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 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] 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 remote host
Syntax:

[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] 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] 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] 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: copy the files of the remote host to the local in batches, which is the opposite of the pscp.pssh command.
Syntax:

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)

Options:

-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] 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

Tags: Linux ssh Python Google

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