Scenario:
You have many servers, one of them has problem when resolving a FQDN. You want to find the server by ping.
example.spy
hostnameToFind = 'problem.domain.com'
## credentials for loging
username = 'user'
password = '123456'
try:
## check a host only, given by CLI
hosts = [__main__.unknown_args[0][1:]]
except IndexError:
## check all hosts
hosts = ['host1','host2','host3','host4','host5'] # and many others here
for host in hosts:
print('checking ',host)
$.connect(f'{username}@{host}',password=password)
with $ as console:
## "0" means not to keey output in memory
console.sendline(f'ping {hostnameToFind}',0)
count = 0
for line in console.lines():
count += 1
## this is important since "ping" runs forever
if count > 5: break
## simply check the IP address on output
print(line)
## explicitly stop the "ping"
console.shutdown()
execution
## check "host1" only
$sshscript example.spy -host1
## check all hosts
$sshscript example.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
- 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 作系統自動化