Skip to main content

running remote commands or scripts with asyncssh

Project description

AsyncSSHScript: running remote commands or scripts with asyncssh

AsyncSSHScript is a Python package which provides an ability to run command or script directly on remote host with AsyncSSH even sudo is required.

import asyncio
import asyncsshscript

async def run_client_test():
    conn = asyncsshscript.AuthHostSession('10.10.10.178',
                               username='yourname',
                               password='yourpassword')
    ret = await conn.connect()
    if not ret:
        print("connection error")
        return


    print("----------command start--------------")
    print( await conn.command('ip a'))
    print("----------command done--------------")

    print("----------sudo command start--------------")
    print(await conn.command('dmidecode', sudo=True))
    print("----------sudo command done--------------")

    print("----------local bash file start--------------")
    print(await conn.bash_file('script_test.sh'))
    print("----------local bash file done--------------")

    print("----------sudo local bash file start--------------")
    print(await conn.bash_file('script_test_sudo.sh', sudo=True))
    print("----------sudo local bash file done-------------")

    print("----------local python file start--------------")
    print(await conn.python_file('script_test.py'))
    print("----------local python file done--------------")

    print("----------local sudo python file start--------------")
    print(await conn.python_file('script_test_sudo.py', sudo=True))
    print("----------local sudo python file done--------------")
    await conn.close()


try:
    asyncio.get_event_loop().run_until_complete(run_client_test())
except (OSError, asyncssh.Error) as exc:
    sys.exit('SSH connection failed: ' + str(exc))

License

Copyright (c) 2020 by NoevilMe and others.

This program and the accompanying materials are made available under the terms of the Eclipse Public License v2.0 which accompanies this distribution and is available at:

http://www.eclipse.org/legal/epl-2.0/

This program may also be made available under the following secondary licenses when the conditions for such availability set forth in the Eclipse Public License v2.0 are satisfied:

GNU General Public License, Version 2.0, or any later versions of that license

SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later

Prerequisites

  • Python 3.6+
  • Asyncssh 2.2+

Installation

Install AsyncSSHScript by running:

pip install asyncsshscript

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

asyncsshscript-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

asyncsshscript-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file asyncsshscript-0.1.0.tar.gz.

File metadata

  • Download URL: asyncsshscript-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for asyncsshscript-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d7b66c1df99e02689c84975aae91187eedded1fc3c92dbd238a19e36cc6c2452
MD5 77128de7242fb28a266a21b93c937ef3
BLAKE2b-256 2f0c3c01d43a72c8696443cf8ab751d7e0073bf64ebe651b7ff27e3ad713622b

See more details on using hashes here.

File details

Details for the file asyncsshscript-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: asyncsshscript-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for asyncsshscript-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b889a0ab9b04e7b6bac8e5b407902f8180a900b6dfdad9bf95e247c800e01f0
MD5 6f10d087f56ad84a8c5831dc4d354bff
BLAKE2b-256 200ac358311295d46f93380b37962b8982ba15a7d673672d7d2dad2df8e5402f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page