通过ssh和docker“in tmux”同时连接到多个主机。

intmux的Python项目详细描述


简介

在tmux中连接到多个ssh/docker主机。

intmux是连接到多个ssh/docker主机的命令行应用程序 在tmux会话中。支持连接到ssh主机、本地docker和 码头工人作曲。

对于每个匹配的主机,intmux将为每个 窗口)并设置tmux同步窗格选项(pass--tmux no sync to turn 关闭),然后运行shell(可通过--command--script或 其他特定于连接方法的开关)。

您可以在tmux会话内部(在其中创建新会话)或外部进行intmux。

ssh

下面的命令创建一个新的tmux会话,其中一个窗口有两个窗格 (一个ssh到host1,另一个ssh到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还可用于连接所有正在运行的本地Docker实例:

# 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容器也可以通过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组合

Docker当前工作目录中所有正在运行的服务都可以 还可以连接到:

# Connect to all containers
intmux compose

# Connect to specific containers:
intmux compose db web

安装

执行:

pip install intmux

帮助

主要帮助:

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帮助:

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帮助:

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撰写帮助:

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帮助:

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.

注释

--script--command将通过ssh建立多个连接(一个可以发送 通过tmux的键,但在不捕获 $?,因此shell命令已与&;)串在一起。也许我会修好的 有一天,但同时,为了限制连接的数量,我建议 通过将以下内容添加到 .ssh/config文件:

ControlMaster auto
ControlPersist 60s
ControlPath /tmp/ssh-%h-%p-%r

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java试图用Mockito模拟IntConsumer失败   java从ArrayList获取一个元素   是否可以调用。。xyz\jdk1。6\bin\java。从jdk1上运行的java程序执行。5\java。exe?   基于连通距离的Kmeans plus聚类算法在java中的应用   java源代码管理是否使Javadoc的@author和@since冗余?   java静态对象引用和非静态对象引用   java如何创建需要动态参数的对象   java试图将字符串添加到一个字符串列表中,但最终将字符串添加到两个字符串列表中。   javacom。凭直觉。ipp。例外Quickbooks中的异常   安全性是对JAR进行模糊处理,足以防止普通最终用户而不是专家黑客理解JAVA代码吗?   scala S3 java API未正确列出文件夹。   java会话超时后重定向到前一个用户上次访问的页面   java Android到excel。jExecl制作0b文件   从jtextfield java GUI向mysql表中插入值   java JMockit和Fest UI测试   单击swing中的add按钮时,java jtextfield从B3001开始递增1