Skip to main content

Parallel SSH with Regex

pypsh is a simple commandline tool to execute a command in parallel on multiple hosts.

Under the hoods it uses ssh via the paramiko python library.

Why pypsh instead of dsh?

Because managing group files with dsh is tedious. Pypsh requires no configuration, it just works.

Similar to dsh, pypsh can be used to execute a command on multiple hosts in parallel. In addition it is also possible to copy a file to multiple hosts at once. See below for further usage instructions.

The command or file copy operation will be executed on any host that is in the known_hosts file and matches the given regular expression.

This means in order for pypsh to know about a host it is necessary to connect to it at least once with plain ssh.

Command Execution

To execute a command on a group of hosts matching a given regular expression:

pypsh <hostregex> <cmd-to-execute>

E.g.:

pypsh "role\d+\.customer\.your\.domain" "uptime"

Instead of executing the commands in parallel it is also possible to execute the commands one after another. To do so use:

pypsh "role\d+\.customer\.your\.domain" --interval 0.1 cmd "uptime"

Or to wait between the commands (which might be useful when restarting services like elasticsearch that are part of a cluster):

pypsh "role\d+\.customer\.your\.domain" -i 60 cmd "uptime"

pypsh can also read from stdin. So it is possible to pipe command into it:

echo "uptime" | pypsh "myhosts[0-9]"

Copy file to multiple hosts

To copy a given file to a group of hosts:

pypsh "my\.domains\d+\.com" copy /tmp/here/myfile.txt /tmp/remote/file.txt

Installation

pypsh can be installed using pip:

pip install pypsh

Development

To work on pypsh checkout the git repository, create a virtual environment and install the dependencies:

git clone https://github.com/mfussenegger/pypsh.git
cd pypsh
mkvirtualenv pypsh
pip install -r requirements.txt

Sometimes it is useful to point the pypsh command to the local development branch:

pip install --upgrade --force-reinstall --editable .

But usually it is sufficient to invoke it like this:

python pypsh/main.py ...

Metadata

Release files for pypsh 0.7.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypsh 0.7.2
File Size Uploaded
pypsh-0.7.2.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pypsh 0.7.2
File Interpreter ABI Platform
pypsh-0.7.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / pypsh-0.7.2.tar.gz

Download URL pypsh-0.7.2.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
900b7ba5f83f08be4c7008a64dbc6105aed3cc3df9a33d62aa9ccb3894abab6f
BLAKE2b-256 checksum
How to use checksums
7966982e66e67f7b90e093f122e7d8f968b862b284be75cccdd438e3e040bb72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pypsh-0.7.2-py3-none-any.whl

Download URL pypsh-0.7.2-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a60bb13dc30553f996b22bde1193144516a9bb6c36af2a5fb0ff085e80510c1d
BLAKE2b-256 checksum
How to use checksums
d549dfb502050f4e1eb959424ee148d0eb9dff7b6b50db4c4176d0dfcbe46c33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.7.3

1 release file

This release

0.7.2 This release

2 release files

0.7.1

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page