Skip to main content

Interactive Parallel SSH jobs manager

Project description

Joknarf Tools Pypi version example Licence Python versions bash

ssh-para

Parallel SSH jobs manager CLI (alternative to parallel-ssh)

  • POSIX/Linux/MacOS/Windows compatible (with openssh client installed)
  • Launch parallel ssh jobs/scripts on remote hosts, with interactive display of the running commands outputs
  • Keep all output in log files
  • Interactive pause/resume/abort jobs, kill stuck ssh connection interactively.

Take a look at run-para if you need to run parallel jobs parameterized

ssh-para3

installation

using pip

pip install ssh-para

or use binary/package in github release assets

By default, ssh-para uses Nerd Fonts glyphs, modern terminals can now render the glyphs without installing specific font (the symbols can be overridden with SSHP_SYM_* environment variables, see below)

quick start

Run command on multiple hosts:
$ ssh-para -H host1 host2 host3 -- echo connection ok
Review last run results:
$ ssh-para -l
Review hosts statuses for last run:
$ ssh-para -L *.status
View failed hosts list:
$ ssh-para -L failed.status
Show output of command on all hosts:
$ ssh-para -L *.out
Show output of command for failed hosts:
$ ssh-para -L *.failed
Show output of command for host1:
$ ssh-para -L host1.out

usage

ssh-para -h
usage: ssh-para [-h] [-V] [-j JOB] [-d DIRLOG] [-m MAXDOTS] [-p PARALLEL] [-t TIMEOUT] [-r] [-v] [-D DELAY]
                [-f HOSTSFILE | -H HOSTS [HOSTS ...] | -C {bash,zsh,powershell} | -l | -L LOGS [LOGS ...]] [-s SCRIPT]
                [-a ARGS [ARGS ...]]
                [ssh_args ...]

ssh-para v1.ssh-para.dev

positional arguments:
  ssh_args

options:
  -h, --help            show this help message and exit
  -V, --version         ssh-para version
  -j JOB, --job JOB     Job name added subdir to dirlog
  -d DIRLOG, --dirlog DIRLOG
                        directory for ouput log files (default: ~/.ssh-para)
  -m MAXDOTS, --maxdots MAXDOTS
                        hostname domain displaylevel (default:1 => short hostname, -1 => fqdn)
  -p PARALLEL, --parallel PARALLEL
                        parallelism (default 4)
  -t TIMEOUT, --timeout TIMEOUT
                        timeout of each job
  -r, --resolve         resolve fqdn in SSHP_DOMAINS
  -v, --verbose         verbose display (fqdn + line for last output)
  -D DELAY, --delay DELAY
                        initial delay in seconds between ssh commands (default=0.3s)
  -f HOSTSFILE, --hostsfile HOSTSFILE
                        hosts list file
  -H HOSTS [HOSTS ...], --hosts HOSTS [HOSTS ...]
                        hosts list
  -C {bash,zsh,powershell}, --completion {bash,zsh,powershell}
                        autocompletion shell code to source
  -l, --list            list ssh-para results/log directories
  -L LOGS [LOGS ...], --logs LOGS [LOGS ...]
                        get latest/current ssh-para run logs
                        -L[<runid>/]*.out          : all hosts outputs
                        -L[<runid>/]<host>.out     : command output of host
                        -L[<runid>/]*.<status>     : command output of hosts <status>
                        -L[<runid>/]*.status       : hosts lists with status
                        -L[<runid>/]<status>.status: <status> hosts list
                        -L[<runid>/]hosts.list     : list of hosts used to connect (resolved if -r)
                        default <runid> is latest ssh-para run (use -j <job> -d <dir> to access logs if used for run)
                        <status>: [success,failed,timeout,killed,aborted]
  -s SCRIPT, --script SCRIPT
                        script to execute
  -a ARGS [ARGS ...], --args ARGS [ARGS ...]
                        script arguments

During run, use :

  • k: to kill ssh command held by a thread (but remote command can still be running on remote host)
  • p: pause all remaining jobs to be scheduled
  • r: resume scheduling of jobs
  • a: abort all remaining jobs
  • ctrl-c: stop all/exit (but remote commands launched by ssh can still be running on remote servers)

Environment variables:

  • SSHP_OPTS: ssh default options (Eg: "-F /home/user/.ssh/myconfig")
  • SSHP_DOMAINS: dns domains to search when short hostname given (with -r/--resolve option)
  • SSHP_SYM_BEG: Symbol character for begin decorative (default: "\ue0b4")
  • SSHP_SYM_END: Symbol character for end decorative (default: "\ue0b6")
  • SSHP_SYM_PROG: Symbol character for progress bar fill (default: "\u25a0")
  • SSHP_SYM_RES: Symbol character before ssh output line (default: "\u25b6")

Activate autocompletion:

  • . <(ssh-para -C bash)
  • ssh-para -C powershell | Out-String | Invoke-Expression

Example

Patch redhat family hosts:

ssh-para -p 20 -f hostlist.txt -- 'sudo yum update -y;sudo shutdown -r +1'

Use specific ssh options / config (everything after -- will be passed to ssh command as is):

ssh-para -p 20 -H host1 host2 -- -F ~/.ssh/myconfig echo connect ok

Launch local script with argument on remote hosts:

ssh-para -p 20 -f hosts.txt -s ./myscript -a status

Extend limited resolv.conf search domains (try to resolve host in each domain, first resolved in the domain list is used as fqdn):

SSHP_DOMAINS="domain1.com domain2.com" ssh-para -r -H host1 host2 -- echo connect ok

Tips

  • ssh-para uses ssh BatchMode, no interactive password/passphrase will be asked, so you need to have a ssh authorized key to connect to servers (ssh-agent...)
  • you need to configure your ssh for StrictHostKeyChecking/UserKnownHostsFile if you need to connect to unknown servers
  • to connect as different user use ssh -l option or define everything in your ssh config file
    • you can use user@host as hostname but not if you need to resolve host (-r/--resolve)
  • if you are using ssh ProxyJump server to reach hosts, you may need to tweak the sshd MaxStartups setting on the ssh Proxy server with high parallelism
    • when ssh-para starts, a delay of 0.3 seconds is applied between threads starting ssh jobs to avoid flooding, (can be tweaked with -D )
  • if you are using remote connexion to launch the ssh-para, use screen to launch ssh-para, as if you lose your connection, ssh-para will be still running and you can re-attach to screen to continue follow-up.
  • Be very carefull when launching massive commands on servers... Always first test on non production.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

ssh_para-1.7.47.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

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

ssh_para-1.7.47-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file ssh_para-1.7.47.tar.gz.

File metadata

  • Download URL: ssh_para-1.7.47.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for ssh_para-1.7.47.tar.gz
Algorithm Hash digest
SHA256 e3105ff671191f8615352b9c96c865af8df7d7b698ffd5979697afb33bdbd691
MD5 bec6c7c8fe1a7c6e425e61085c0e0011
BLAKE2b-256 ab24b33b91f0a13ebcb7c5eb8c044bf4a720391bcbedc7e0cd8c76dab0fdbc65

See more details on using hashes here.

File details

Details for the file ssh_para-1.7.47-py3-none-any.whl.

File metadata

  • Download URL: ssh_para-1.7.47-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for ssh_para-1.7.47-py3-none-any.whl
Algorithm Hash digest
SHA256 80032c47be8f24cb32d0dd2d3be9ecd943e4894186fc49a2b327ac4c343c26d4
MD5 a73beafed8ecfff2d158cd55a40c9b8a
BLAKE2b-256 b9c0b290c87e727b0eb11e8d96f64334b1ede5e70c2c5045f35aca17cd9b6f70

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