Connect to multiple hosts simultaneously "in tmux" via ssh and docker.
Project description
Introduction
Connect to multiple ssh/docker hosts "in tmux".
intmux is a command line application to connect to multiple ssh/docker hosts within a tmux session. Supports connections to SSH hosts, local docker and docker-compose.
For each matching host intmux will create a new pane (up to --tmux-panes per
window) and set the tmux synchronize-panes options (pass --tmux-no-sync to turn
this off), and run a shell (configurable via --command, --script or
other switches specific to the connection method).
You can intmux inside a tmux session (creates a new session within it) or out.
SSH
The following command creates a new tmux session with one window with two panes (one ssh'd to host1, another to user@host2):
intmux ssh host1 user@host2
# Connect to hosts listed in inputfile.txt
intmux -i inputfile.txt ssh
# Connect to hosts, with a separate window for each host
intmux --tmux-panes 1 ssh host1 user@host2
# Connect and tail the syslogs:
intmux --command 'sudo tail -f /var/log/syslog' ssh host1 user@host2
# Run a script (copies local script to remote host, and executes it)
intmux --script ./local_script.sh ssh host1 user@host2
Docker
intmux can also be used to connect to all running local docker instances:
# Connect to all local containers
intmux docker
# Connect to specific containers
intmux docker a_name f947ff94a995
# Look at logs on hosts:
intmux docker --docker-command 'logs -f' a_name f947ff94a995
Docker containers can also be connected to over SSH:
# Connect to all remote containers on two different hosts
intmux ssh-docker host1 user@host2
# Connect to specific containers
intmux ssh-docker --docker-containers "a_name,f947ff94a995" host1 user@host2
# Look at logs on hosts:
intmux ssh-docker --docker-command 'logs -f' --docker-containers "a_name,f947ff94a995" host1 user@host2
Docker-compose
All running services of the docker-compose in your current working directory can also be connected to:
# Connect to all containers
intmux compose
# Connect to specific containers:
intmux compose db web
Installation
Execute:
pip install intmux
Help
Main help:
intmux --help
usage: intmux [-h] [--log LOG] [--command COMMAND] [--input INPUT]
[--script SCRIPT] [--tmux-panes PANES] [--tmux-sync]
[--tmux-session SESSION]
{ssh,docker,ssh-docker,compose} ...
Connect to several hosts in a tmux session.
positional arguments:
{ssh,docker,ssh-docker,compose}
sub-command help
ssh Connect to hosts via SSH
docker Connect to docker containers via 'docker exec'
ssh-docker Connect to docker containers on remote SSH hosts
compose Connect to docker containers associated with current
docker-compose via 'docker exec'
optional arguments:
-h, --help show this help message and exit
--log LOG, -l LOG Log level (default: WARN)
--command COMMAND, -c COMMAND
Command to execute when connecting to a remote host
--input INPUT, -i INPUT
Read list of hosts from input file when provided.
--script SCRIPT, -s SCRIPT
Execute commands in local file remotely (executes over
--command option)
--tmux-panes PANES, -p PANES
Max tmux panes per window (default: 6)
--tmux-no-sync, -S Do not run tmux's set-option synchronize-panes
--tmux-session SESSION, -t SESSION
tmux session name (default: intmux)
SSH help:
intmux ssh -h
usage: intmux ssh [-h] [--ssh-options SSH_OPTIONS] [hosts [hosts ...]]
Connect to the provided hosts.
positional arguments:
hosts SSH hosts to connect to.
optional arguments:
-h, --help show this help message and exit
--ssh-options SSH_OPTIONS, -so SSH_OPTIONS
Options to pass to SSH connection.
Docker help:
intmux docker -h
usage: intmux docker [-h] [--docker-command DOCKER_COMMAND] [--approximate]
[hosts [hosts ...]]
Connect to the provided running containers
positional arguments:
hosts List of docker containers to connect to (default:
connect to all containers)
optional arguments:
-h, --help show this help message and exit
--docker-command DOCKER_COMMAND, -dc DOCKER_COMMAND
Docker command to execute (default: 'exec -it {}
bash'). If '{}' is included in the command, the docker
host is substituted there, the host is appended. NOTE:
may invalidate any --script/--command parameters if a
shell is not provided.
--approximate, -a Include any docker container names that only partially
match hosts.
Docker Compose help:
intmux compose -h
usage: intmux compose [-h] [--docker-command DOCKER_COMMAND] [--approximate]
[hosts [hosts ...]]
Connect to containers associated with the docker-compose in the current
directory.
positional arguments:
hosts List of docker containers to connect to (default:
connect to all containers)
optional arguments:
-h, --help show this help message and exit
--docker-command DOCKER_COMMAND, -dc DOCKER_COMMAND
Docker command to execute (default: 'exec -it {}
bash'). If '{}' is included in the command, the docker
host is substituted there, the host is appended.
--approximate, -a Include any docker container names that only partially
match hosts.
SSH Docker help:
intmux ssh-docker -h
usage: intmux ssh-docker [-h] [--ssh-options SSH_OPTIONS]
[--docker-containers DOCKER_CONTAINERS]
[--docker-command DOCKER_COMMAND] [--approximate]
[hosts [hosts ...]]
Connect to docker containers on provided SSH hosts
positional arguments:
hosts SSH hosts to connect to.
optional arguments:
-h, --help show this help message and exit
--ssh-options SSH_OPTIONS, -so SSH_OPTIONS
Options to pass to SSH connection.
--docker-containers DOCKER_CONTAINERS, -dC DOCKER_CONTAINERS
Comma separated list of docker containers to connect
to (default: connect to all containers)
--docker-command DOCKER_COMMAND, -dc DOCKER_COMMAND
Docker command to execute (default: 'exec -it {}
bash'). If '{}' is included in the command, the docker
host is substituted there, the host is appended. NOTE:
may invalidate any --script/--command parameters if a
shell is not provided.
--approximate, -a Include any docker container names that only partially
match hosts.
Notes
--script and --command will make multiple connections over SSH (one can send
keys over tmux, but not easily track success of without capturing the result of
$?, so shell commands have been string together with &&). Maybe I'll fix that
some day, but in the meantime, to limit the number of connections I suggest
turning on SSH ControlMaster settings by adding the following to your
.ssh/config file:
ControlMaster auto
ControlPersist 60s
ControlPath /tmp/ssh-%h-%p-%r
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file intmux-0.8.0.tar.gz.
File metadata
- Download URL: intmux-0.8.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5180282ccedce066d5a8f69d4683aef00ad271527a8f1f2f8aa514bc898f29e5
|
|
| MD5 |
15877b6bedf0534a6cdb9f2ca230a6d5
|
|
| BLAKE2b-256 |
3efdf3f36128b655438df3db023895773e169b77f708205609fa8dd3d10a141b
|
File details
Details for the file intmux-0.8.0-py3.6.egg.
File metadata
- Download URL: intmux-0.8.0-py3.6.egg
- Upload date:
- Size: 16.7 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a53c3246386ef7ba7aa22439c7b04561492694d1f449aa7292db00794615098
|
|
| MD5 |
a24598dfbcac886600c6341344afdac8
|
|
| BLAKE2b-256 |
a9361674c86ed045c8286f479f189dc6e7127d4b7e5dd7188b652633aa1d89e4
|