concurrent-ssh
Executing commands with ssh concurrently on multiple hosts using asyncio
Installation
pip install concurrent-ssh
# Or from the latest GitHub version
pip install git+https://github.com/DCsunset/concurrent-ssh
Usage
Note: ensure that ssh is in your PATH environment variables.
CLI
Use -H or --hosts to specify the hosts to run the commands on:
cssh -H <host1> <host2> .... <host_n> -- <command>
# pass extra ssh options
cssh -o="-q -4" -H <host1> <host2> .... <host_n> -- <command>
# read hosts from file
cssh -f hosts.txt -- <command>
Note that -- is necessary to separate the options and the command.
For -o/--options to work correctly, use = to prevent it from being parsed as another option.
The standard input (stdin) of the cssh process is piped to the stdin of every spawned processes.
cssh can handle signals as follows:
- Upon receiving one
SIGINT(including keyboard interrupt) orSIGTERM,csshwill sendSIGTERMto all spawned processes. - Upon receiving more than one of them,
csshwill instead sendSIGKILLto kill all spawned processes.
Library
It can also be used as a library:
import asyncio
from cssh.executor import SshExecutor
async def main():
hosts = ["host1", "host2"]
executor = SshExecutor(hosts)
# running concurrently
await executor.run("some_command --test")
# access stdout for all hosts (or stderr)
async for host, out in executor.stdout:
print(f"{host}: {out}")
# wait until all finished
ret_codes = await executor.wait()
asyncio.run(main())
See more usage in cssh/cli.py.
Development
To set up the development environment, first clone this repo.
Then it's recommended to usevenv:
# suppose PWD is the root dir of the repo
python -m venv venv
# activate the environment``
source venv/bin/activate
pip install -r requirements.txt
To deactivate, run deactivate.
License
This project is licensed under AGPL-3.0. Copyright notice:
concurrent-ssh
Copyright (C) 2023 DCsunset
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Metadata
Release files for concurrent-ssh 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| concurrent-ssh-0.3.1.tar.gz | 17.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| concurrent_ssh-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.5 kB
Release files / concurrent-ssh-0.3.1.tar.gz
| Download URL | concurrent-ssh-0.3.1.tar.gz |
|---|---|
| Size | 17.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ca5b4eb124aa8ea1054b5852b82b26424f12e238734c82f537bc5ca5ecfe706d
|
|
BLAKE2b-256 checksum How to use checksums |
7d5feb9a0d62a3e0b8dd6664141b0231630b9256212abac9847848086217dc31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / concurrent_ssh-0.3.1-py3-none-any.whl
| Download URL | concurrent_ssh-0.3.1-py3-none-any.whl |
|---|---|
| Size | 19.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
719e160d17df3cccf5fb317c7f72265c56a08976f1c7bfc9a818ed7a36f60060
|
|
BLAKE2b-256 checksum How to use checksums |
f2f6059a44f3bae8815e5b5a31d5307c020c5d9baf80549dbe6ab8c62b6381fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Security for concurrent-ssh 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.