Scenario:
ssh to remote hosts and run commands in parallel by threads.

Note: this example requires sshscript version >= 1.1.12
file: example.spy
# If the localhost can connect host-b, host-c directly,
# We don't need to connect bridge host, just comment-out the next line.
$.connect('user@host-a')
$ hostname
print('connected to',$.stdout)
# if you are interested of its outupt
# os.environ['VERBOSE'] = '1'
def job(account,pkey,ret):
# this example shows how to load private key for authentication
$.connect(account,pkey=pkey)
# executing command
$ hostname
ret['hostname'] = $.stdout
# executing command
$ date
ret['date'] = $.stdout
$.close()
pkey = $.pkey('/home/user/.ssh/id_rsa')
# invoking thread-1
ret1 = {}
t1 = $.thread(target=job,args=('user@host-b', pkey, ret1))
# invoking thread-2
ret2 = {}
t2 = $.thread(target=job,args=('user@host-c',pkey, ret2))
t1.start()
t2.start()
t1.join()
t2.join()
print(ret1)
print(ret2)
execute the example.spy
$sshscript example.spy
$sshscript example.spy --verbose
$sshscript example.spy --debug
$sshscript example.spy --debug --verbose
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
- Page not found
- Q: What can it do that Netmiko doesn’t do? (origin)
- SSHScript Documentation
- 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 作系統自動化