[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Login to device shell


On Apr 18, 2014 9:55 PM, "Mal" <Malz@xxxxxxxxxx> wrote:

>  Hello
>
>
>
> I am wondering if anyone has written a trivial C program to login to an
> ssh service and execute a simple console command, collect the output and
> display from the program prompt.
>
>
From the PySecure project. It follows the library closely with identical
naming, and has a very clean syntax:

(
https://github.com/dsoprea/PySecure/blob/master/pysecure/adapters/ssha.py#L476
)


def execute(self, cmd, block_size=DEFAULT_EXECUTE_READ_BLOCK_SIZE):
    """Execute a remote command. This functionality does not support more
    than one command to be executed on the same channel, so we create a
    dedicated channel as the session level than allowing direct access at
    the channel level.
    """

    with SshChannel(self) as sc:
        self.__log.debug("Executing command: %s" % (cmd))

        sc.open_session()
        sc.request_exec(cmd)

        buffer_ = bytearray()
        while 1:
            bytes = sc.read(block_size)
            yield bytes

            if len(bytes) < block_size:
                break



Dustin


>
> I have tried to follow the tutorial example with no success..
>
>
>
> Mal
>
>
>
>
>

References:
Login to device shellMal <Malz@xxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org