Skip to main content

Run commands across multiple servers over SSH — parallel, with jump host support and broadcast shell.

Project description

sshrunner 🚀

A lightweight Python module for running commands across multiple servers simultaneously over SSH — with parallel execution, jump host support, per-host log saving, and an interactive broadcast shell.


Features

  • Parallel execution — runs commands on all hosts concurrently via threads
  • 🔐 SSH key & jump host support — works with bastion/proxy servers
  • 📁 Per-host log files — timestamped output saved automatically
  • 🖥️ Interactive broadcast mode — type once, runs everywhere
  • 🔧 Per-host port override — perfect for Docker/local testing

Installation

pip install sshrunner

paramiko>=3.0 is installed automatically as a dependency.


Quick Start

from sshrunner import SSHRunner

runner = SSHRunner(
    hosts=["web1.example.com", "web2.example.com", "db1.example.com"],
    username="deploy",
    key_path="~/.ssh/id_rsa",
    output_dir="./ssh_logs",
)

results = runner.run("uptime")
runner.print_results(results)

runner.run() returns a list of HostResult objects, one per host. Each result exposes:

Attribute Type Description
host str Host address (and port if non-default)
stdout str Standard output from the command
stderr str Standard error from the command
exit_code int | None Exit code returned by the remote command
error str | None Connection or execution error message, if any
duration float Time taken in seconds
ok bool True if no error and exit_code == 0

Docker Testing

Spin up local SSH containers for testing without real servers:

docker-compose -f docker-compose.test.yml up -d
python examples/test_docker.py

See docker-compose.test.yml and examples/test_docker.py for full details.


Per-host port support

from sshrunner import SSHRunner, Host

runner = SSHRunner(
    hosts=[
        Host("localhost", port=2221),
        Host("localhost", port=2222),
        Host("localhost", port=2223),
    ],
    username="testuser",
    password="testpass",
)

Jump host (bastion)

runner = SSHRunner(
    hosts=["10.0.1.10", "10.0.1.11"],
    username="deploy",
    key_path="~/.ssh/id_rsa",
    jump_host="bastion.mycompany.com",
    jump_username="bastion-user",   # defaults to username if omitted
    jump_key_path="~/.ssh/bastion_rsa",  # defaults to key_path if omitted
    jump_port=22,  # defaults to 22
)

Interactive broadcast mode

runner.interactive()
# all> tail -f /var/log/app.log   ← runs on every host simultaneously

Type exit or press Ctrl-C to close all sessions.


Configuration Reference

SSHRunner

Parameter Default Description
hosts List of hostnames, IPs, or Host(addr, port) objects
username SSH username
key_path None Path to private key (~ expanded)
password None Password auth (key preferred)
port 22 Default SSH port for all hosts
jump_host None Bastion/jump host address
jump_username username SSH username for the jump host
jump_key_path key_path Private key for the jump host
jump_port 22 SSH port for the jump host
output_dir None Directory to save per-host log files
connect_timeout 10 Connection timeout in seconds
max_workers 20 Max parallel threads

print_results(results, show_stderr=True)

Parameter Default Description
results List of HostResult objects returned by run()
show_stderr True Whether to print stderr output for each host

Roadmap

  • YAML/JSON host inventory file support
  • CLI interface (sshrunner --hosts-file servers.yml "uptime")
  • Colored terminal output
  • Retry logic for flaky connections
  • Async backend option (asyncssh)

Requirements


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sshrunner-0.1.2.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sshrunner-0.1.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file sshrunner-0.1.2.tar.gz.

File metadata

  • Download URL: sshrunner-0.1.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for sshrunner-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7ed753bedabb9632052be6c0bcc2057bc3ca64565cddf0bab035160a5cc036e2
MD5 0c7707dd6f387cf34a06470858d7c667
BLAKE2b-256 fbdb1d067966d315104988cc191844c8eff7b05642a88afedcfb0b7b96e3ef13

See more details on using hashes here.

File details

Details for the file sshrunner-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sshrunner-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for sshrunner-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c8c2f45800bdf009fe349f73743db8d5f83b55247ba5316c1fe38698860e95e3
MD5 ae187a3fbaf52071c7ca9fb05c57bd2a
BLAKE2b-256 1f38b33f6a49ae7507002e8d86c099f590274e7f8f92549f37264060aadc5459

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page