Skip to main content

Execute commands on multiple remote SSH sessions

Project description

ssh_session_manager

Execute commands on multiple remote SSH sessions

PyPI

Example 1: Using the SSHSession

#!/usr/bin/env python

from ssh_session_manager.Command import Command
from ssh_session_manager.SSHSession import SSHSession


ssh_session = SSHSession("Silver Server", "10.0.0.57", "user", "password")

ls_command = Command("ls -la")
ps_command = Command("ps -ax")

commands = [
    ls_command,
    ps_command
]

ssh_session.open_ssh_session()

for command in commands:
    ssh_session.run_command_in_ssh_session(command)

ssh_session.close_ssh_session()

command_output_dictionary = ssh_session.get_command_output_dictionary(ps_command)

standard_output_lines = command_output_dictionary["standard_output_lines"]
standard_error_lines = command_output_dictionary["standard_error_lines"]
exit_status = command_output_dictionary["exit_status"]

Example 2: Using the SSHSessionManager

#!/usr/bin/env python

from ssh_session_manager.Command import Command
from ssh_session_manager.SSHSession import SSHSession
from ssh_session_manager.SSHSessionManager import SSHSessionManager


ssh_session_1 = SSHSession("Silver Server", "10.0.0.57", "user", "password")
ssh_session_2 = SSHSession("Black Server", "10.0.0.57", "user", "password")

ssh_sessions = [
    ssh_session_1,
    ssh_session_2
]

ls_command = Command("ls -la")
ps_command = Command("ps -ax")

commands = [
    ls_command,
    ps_command
]

ssh_session_manager = SSHSessionManager(ssh_sessions)
ssh_session_manager.open_all_ssh_sessions()
ssh_session_manager.run_commands_in_ssh_sessions(commands)
ssh_session_manager.close_all_ssh_sessions()

command_output_dictionary = ssh_session_manager.get_command_output_dictionary(ssh_session_1, ls_command)

standard_output_lines = command_output_dictionary["standard_output_lines"]
standard_error_lines = command_output_dictionary["standard_error_lines"]
exit_status = command_output_dictionary["exit_status"]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssh-session-manager-0.4.0.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file ssh-session-manager-0.4.0.tar.gz.

File metadata

  • Download URL: ssh-session-manager-0.4.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.5

File hashes

Hashes for ssh-session-manager-0.4.0.tar.gz
Algorithm Hash digest
SHA256 879d4a059f1fb10dcb8e671b7933734199add1ab7a8483edc2ee46f5293cc29d
MD5 472fdd11787ff2a743908b5584d41f89
BLAKE2b-256 9024c354916e4d0980d967aaa5ebedf40dcf5545ab183e3319eaca6399a4d87a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page