Skip to main content

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

Metadata

Release files for asyncsshscript 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asyncsshscript 0.1.0
File Size Uploaded
asyncsshscript-0.1.0.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asyncsshscript 0.1.0
File Interpreter ABI Platform
asyncsshscript-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 kB

Release files / asyncsshscript-0.1.0.tar.gz

Download URL asyncsshscript-0.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d7b66c1df99e02689c84975aae91187eedded1fc3c92dbd238a19e36cc6c2452
BLAKE2b-256 checksum
How to use checksums
2f0c3c01d43a72c8696443cf8ab751d7e0073bf64ebe651b7ff27e3ad713622b
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / asyncsshscript-0.1.0-py3-none-any.whl

Download URL asyncsshscript-0.1.0-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b889a0ab9b04e7b6bac8e5b407902f8180a900b6dfdad9bf95e247c800e01f0
BLAKE2b-256 checksum
How to use checksums
200ac358311295d46f93380b37962b8982ba15a7d673672d7d2dad2df8e5402f
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page