Skip to main content

write automation scripts for ssh and subprocess in python

Project description

SSHScript makes Python become a scripting tool for system automation. Functionally, the SSHScript is something like the Ansible. Instead of writing descriptive YML files, just write Python scripts with the simplicity of Python and the power of all Python packages.

Technically, the SSHScript is an integration of subprocess and Paramiko . It provides an unique interface to invoke commands locally and remotely. Something like embedding shell commands in a python script.

Below are three examples:

# example 1: demo.spy
# execute a command on localhost and parse the output with python
$netstat -ant
for line in $.stdout.split('\n'):
    if not line.endswith('LISTEN'): continue
    print(line)

# example 2: demo.spy
# by adding one line to make connection.
# you can do the same thing on remote host-a
$.connect('user@host-a',password='19890604')
$netstat -ant
for line in $.stdout.split('\n'):
    if not line.endswith('LISTEN'): continue
    print(line)

# example 3: demo.spy
# by adding two lines to make connections.
# you can do the same thing on remote host-b which is behind host-a
$.connect('user@host-a',password='19890604')
$.connect('user@host-b',password='19890604')
$netstat -ant
for line in $.stdout.split('\n'):
    if not line.endswith('LISTEN'): continue
    print(line)

Execution

$ sshscript demo.spy

Installation

pip install sshscript

Why and Features

The idea is that many automation tasks are running commands and dealing with outputs on localhost and remote hosts. Among these scripts, there are many common routines. Eg. making ssh connections, execution and collecting data. That’s where the SSHScript comes into play. The most charming part is that you could directly process the resulting data in Python. It then enables you to efficiently build complex data structures and processing flow with object-oriented approaches.

  • Easy to script. If you know what commands to run and which host to ssh, then you can write your script. No extra stuff to learn.

  • Embedding shell commands in Python scripts are intuitive and self-explaining. It is good for teamwork and maintenance.

  • Handling execution output or exceptions with Python is easier than shell script.

  • Your scripts are powered by tons of Python packages.

  • With thread support.

More

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

sshscript-1.1.12.tar.gz (22.8 kB view details)

Uploaded Source

File details

Details for the file sshscript-1.1.12.tar.gz.

File metadata

  • Download URL: sshscript-1.1.12.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.9

File hashes

Hashes for sshscript-1.1.12.tar.gz
Algorithm Hash digest
SHA256 4d6af049ff43ccb5bfab265990e52e98ba0f2c69d217d5b443da30e926b33241
MD5 ef92933309604fc6bd8e7f8f196163b9
BLAKE2b-256 0b2e3a27920a5cb4aebb79f222dc0179a65e8d1e5b6b1a9c8b715e7f99803bf1

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