Skip to content

Instantly share code, notes, and snippets.

@V346Cen
Last active November 2, 2022 14:00
Show Gist options
  • Save V346Cen/367f9fc20cfa471567ac6f71f5efa51b to your computer and use it in GitHub Desktop.
Save V346Cen/367f9fc20cfa471567ac6f71f5efa51b to your computer and use it in GitHub Desktop.
import sys
from pssh.exceptions import AuthenticationException
from pssh.clients import ParallelSSHClient
import pssh.utils
host = '192.168.255.1'
cmd = 'uname -a'
pssh.utils.enable_debug_logger()
client = ParallelSSHClient([host],
user='myuser',
pkey='~/.ssh/mykey',
num_retries=1)
try:
output = client.run_command(cmd)
except AuthenticationException:
sys.exit(1)
for host_out in output:
for line in host_out.stdout:
print(line)
2022-11-02 14:05:04,472 DEBUG pssh.clients.base.parallel Make client request for host 192.168.255.1, (host_i, host) in clients: False
2022-11-02 14:05:04,525 DEBUG pssh.clients.base.single Connecting to 192.168.255.1:22
2022-11-02 14:05:04,641 DEBUG pssh.clients.base.single Proceeding with private key authentication
2022-11-02 14:05:04,641 DEBUG pssh.clients.base.single Private key is provided in bytes, using as private key data
2022-11-02 14:05:04,652 ERROR pssh.clients.base.parallel Failed to run on host 192.168.255.1 - ('Authentication error while connecting to %s:%s - %s - retries %s/%s', '192.168.255.1', 22, AuthenticationError(), 1, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment