sshscript module
You can import sshscript in regular python script. For example:
import sshscript
paths = []
for filename in os.listdir('my-project'):
if filename.endswith('.spy'):
paths.append('my-project/'+filename)
sshscript.runFile(paths)
sshscript.runFile()
This function executes .spy files, it has following parameters:
- paths: a file path(str) or a list of file path, this is required. List items could be path of file, folder or wildcard. You can find more details in the “sshscript CLI”.
- varGlobals: a dict to update the globals(), the default is None.
- varLocals: a dict to update the locals(), the default is None.
- showScript: if True, show converted script. No execution. The default is False.
- showRunOrder: if True, show files in order of running. No execution. The default is False.
- unisession: if True, run all files in a single session. If False, run every file in a new session. The default is True.
import sshscript
sshscript.runFile('0.spy')
sshscript.runFile('a*.spy')
sshscript.runFile('/home/myproject/')
sshscript.runFile(['0.spy','1.spy'],None,locals())
sshscript.runScript()
This function executes .spy script, it has following parameters:
- script: string of SSHScript script to execute. This is required.
- varGlobals: a dict to update to the glocals(), the default is None.
- varLocals: a dict to update the locals(), the default is None.
import sshscript
username = 'tim'
def say(hostname):
print('hostname:', hostname)
script= '''
$.open(f'{username}@host') #⬅ "username" is available
$hostname
say($.stdout) #⬅ "say" is available
'''
sshscript.runScript(script,globals(),locals())
Last Updated: 2026-07-25 16:59:40
Table of contents
- SSHScript v3.1 Documentation
- Accounts (legacy URL)
- Checking the syncing status of two MySQL servers
- Getting Started with SSHScript
- Q: What can it do that Netmiko doesn’t do? (origin)
- SSHScript Documents
- SSHScript v2.0 CLI(Draft)
- SSHScript v2.0 Commands Execution and Console
- SSHScript v2.0 Console of sudo and su
- SSHScript v2.0 Getting Started
- SSHScript v2.0 Interactive Commands and Foreground Commands
- SSHScript v2.0 Make Connections
- SSHScript v2.0 Recipes
- SSHScript v2.0 Reference Guide
- SSHScript v2.0 Stdout, Stderr and Exitcode
- SSHScript v2.0 Threading Support
- SSHScript v2.0 Upload and Download Files
- SSHScript v2.0.2 Release Notes
- SSHScript v3.0 Interactive and Foreground Commands
- SSHScript v3.0 Reference Guide
- SSHScript v3.0.0 Release Notes
- SSHScript v3.1
- SSHScript vs. Ansible
- 用 Python 作系統自動化