Skip to content

After connecting via ssh contrib command, execute multiple commands in the same session #701

Answered by sla-te
sla-te asked this question in Q&A
Discussion options

You must be logged in to vote

This is what I ultimately came up with:

from dataclasses import dataclass, field
from time import sleep
from typing import Any

import sh

@dataclass(slots=True)
class MasterSlaveSsh:
    master: Any = field(
        init=False,
        default_factory=lambda: sh.ssh.bake(
            "-o", "ControlMaster=yes", "-o", "ControlPath=~/.ssh/control-10.0.0.1_root", "-i", "priv_key", "root@10.0.0.1"
        ),
    )
    slave: Any = field(
        init=False,
        default_factory=lambda: sh.ssh.bake("-o", "ControlPath=~/.ssh/control-10.0.0.1_root", "-i", "priv_key", "root@10.0.0.1"),
    )

    def __enter__(self) -> slave:
        is_connected: bool = False

        def assert_connected(line)…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@amoffat
Comment options

@sla-te
Comment options

Comment options

You must be logged in to vote
1 reply
@amoffat
Comment options

Answer selected by sla-te
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants