Using ping to check network quality
Server group A has members A1, A2, …, A10, which share the same database server B. You want to regularly check the connection states from group A to B. This example shows how to connect to all servers in group A and execute the “ping” command to database server B.

## filename: example-ping.spy
databaseServer = '192.168.1.100'
## suppose they share the same credentials
username = 'user'
password = '1234'
groupsA = []
for i in range(10):
groupsA.append([f'{username}@hostA{i+1}',password)
## This keeps average speeds of "ping"
states = {}
for account,password in group:
with $.connect(account,password) as host:
$f'ping -c 3 -W 3 {databaseServer}'
## find the bottom line of output
## eg. 3 packets transmitted, 3 received, 0% packet loss, time 2003ms
if 'transmitted' in line:
words = line.split()
received, time = int(words[3]),words(cols[9][:-2])
avg = sum(times)/len(times) if len(times) else 0
states[account] = time / received if received else 0
Executing
$sshscript example-ping.spy
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 作系統自動化