Skip to main content

System automation is the process of repeating network and execution operations to achieve desired results. SSHScript is a Python library that makes it easy to create system automation processes. It provides a simple and intuitive interface for executing commands on local and remote hosts, without requiring any knowledge of the subprocess module or Paramiko (SSH).

SSHScript is technically an integration of the subprocess and Paramiko modules, but it presents an unified interface that is more convenient and expressive for system automation tasks. It is also pure Python, which means that SSHScript scripts can be easily integrated with other Python libraries and tools.

Here is an example of a simple script in SSHScript syntax(v2):

## filename: example.spy
## run: sshscript example.spy
$hostname
## get output by $.stdout, $.stderr and $.exitcode
print('localhost name is ', $.stdout.strip())
## get an interactive sudo console of locahost
with $.sudo('password') as sudoconsole:
    sudoconsole.exec_command('whoami')
    assert 'root' in sudoconsole.stdout
    sudoconsole.exec_command('ls -l $HOME')

## connect to remote by ssh
with $.connect('user1@host', 'password):
    $hostname
    ## get output by $.stdout, $.stderr and $.exitcode
    print('remote name is ', $.stdout.strip())
    ## get an interactive sudo console of remote host
    with $.sudo('password') as sudoconsole:
        sudoconsole.exec_command('whoami')
        assert 'root' in sudoconsole.stdout
        sudoconsole.exec_command('ls -l $HOME')
    with $.connect('user2@nestedhost', pkey=$.pkey('/home/user1/.ssh/id_rsa')):
        $hostname
        ## get output by $.stdout, $.stderr and $.exitcode
        print('nested remote name is ', $.stdout.strip())
        ## get an interactive sudo console of remote host
        with $.sudo('password') as sudoconsole:
            sudoconsole.exec_command('whoami')
            assert 'root' in sudoconsole.stdout
            sudoconsole.exec_command('ls -l $HOME')

Here is an example of a simple script with SSHScript module(v2):

## filename: example.py
## run: python3 example.py
import sshscript
from sshscript import SSHScriptSession
session = SSHScriptSession()
# Execute a command on the local host
session.exec_command('df')
for line in session.stdout.split('\n'):
    cols = line.split()
    if len(cols)>5: print(f'ussage of {cols[0]} is {cols[4]}')
## connect to remote by ssh
with session.connect('user1@host', 'password) as remote_session:
    # Execute a command on the remote host
    remote_session.exec_command('df')
    for line in remote_session.stdout.split('\n'):
        cols = line.split()
        if len(cols)>5: print(f'ussage of {cols[0]} is {cols[4]}')
    with remote_session.connect('user2@nestedhost', pkey=remote_session.pkey('/home/user1/.ssh/id_rsa') as nested_remote_session:
        # Execute a command on the remote host
        nested_remote_session.exec_command('df')
        for line in nested_remote_session.stdout.split('\n'):
            cols = line.split()
            if len(cols)>5: print(f'ussage of {cols[0]} is {cols[4]}')

SSHScript can be used to automate a wide variety of system tasks, such as:

  • Deploying and configuring servers

  • Managing backups and restores

  • Monitoring and troubleshooting systems

  • Automating repetitive tasks

SSHScript is a powerful tool for system automation, and it is easy to use, even for those with limited programming experience.

Releases

The new experimental release is 2.0.2 (2023/10/6). There are lots of changes, but documentation is on working.

The last stable version is 1.1.17. (2022/9/22). Relase Notes

More

Release files for sshscript 2.0.2

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

Source distribution (sdist)

Source distribution for sshscript 2.0.2
File Size Uploaded
sshscript-2.0.2.tar.gz 51.0 kB Details

Release files / sshscript-2.0.2.tar.gz

Download URL sshscript-2.0.2.tar.gz
Size 51.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1f80afb554f8e1b95ebda93b3577d9d1f1fcb6311e37872c83185587fbeafb06
BLAKE2b-256 checksum
How to use checksums
f87ecaf418927819d2906ba295cadb2f4248d40f300d26b06064ce1080d07e5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.18

Release history Release notifications | RSS feed

This release

2.0.2 This release

1 release file

1.1.17

1 release file

1.1.16

1 release file

1.1.14

1 release file

1.1.12

1 release file

1.1.7

1 release file

1.1.6

1 release file

0.992

1 release file

0.986

1 release file

0.985

1 release file

0.984

1 release file

0.983

1 release file

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