Commit e286490b authored by Simon Redman's avatar Simon Redman

Add ssh helper for getting exit codes of commands

parent e66a38a3
......@@ -18,6 +18,7 @@
import getpass
import sys
from pexpect import pxssh
from typing import List
DEFAULT_SSH_OPTIONS = {"StrictHostKeyChecking": "no",
......@@ -165,3 +166,15 @@ def run_commands_on_many_hosts(sessions, commands):
outputs.append(output)
return outputs
def get_exit_codes(sessions) -> List[int]:
"""
Get the exit code of the last command run in each session
"""
commands = ["echo $?" for session in sessions]
codes = run_commands_on_many_hosts(sessions, commands)
codes = [code.split()[2] for code in codes] # Get just the return code (not the echo'ed command)
codes = [int(code) for code in codes]
return codes
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment