Execute commands on multiple remote SSH sessions
Project description
ssh_session_manager
Execute commands on multiple remote SSH sessions
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for ssh-session-manager-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 879d4a059f1fb10dcb8e671b7933734199add1ab7a8483edc2ee46f5293cc29d |
|
MD5 | 472fdd11787ff2a743908b5584d41f89 |
|
BLAKE2b-256 | 9024c354916e4d0980d967aaa5ebedf40dcf5545ab183e3319eaca6399a4d87a |