From fed5e4953cb922970c78cb052c60171b9aa2da03 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste VESLIN Date: Fri, 5 Mar 2021 10:05:00 +0100 Subject: [PATCH 1/3] fix: don't exit(1) if both err and out are not empty --- app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 1ad11f7..953a211 100644 --- a/app.py +++ b/app.py @@ -105,7 +105,8 @@ def ssh_process(ssh, input_ssh): err = err.strip() if err is not None else None if err: print(f"Error: \n{err}") - sys.exit(1) + if out is None: + sys.exit(1) pass From 1e8a5783bc1b2bc2bdb765165e2538f7cd6a4e3a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste VESLIN Date: Fri, 5 Mar 2021 10:18:23 +0100 Subject: [PATCH 2/3] feat: use ssh command exit code --- app.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app.py b/app.py index 953a211..2feb9ba 100644 --- a/app.py +++ b/app.py @@ -96,6 +96,9 @@ def ssh_process(ssh, input_ssh): stdin, stdout, stderr = ssh.exec_command(command_str) + ssh_exit_status = stdout.channel.recv_exit_status() + print(f"ssh exit status: {ssh_exit_status}") + out = "".join(stdout.readlines()) out = out.strip() if out is not None else None if out: @@ -107,6 +110,9 @@ def ssh_process(ssh, input_ssh): print(f"Error: \n{err}") if out is None: sys.exit(1) + if ssh_exit_status != 0: + print(f"ssh exit status: {ssh_exit_status}") + sys.exit(1) pass From 5aa3c5e8d1f0297b155aa77c94792d9f1f69f8ef Mon Sep 17 00:00:00 2001 From: Jean-Baptiste VESLIN Date: Fri, 5 Mar 2021 10:36:08 +0100 Subject: [PATCH 3/3] Update app.py --- app.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app.py b/app.py index 2feb9ba..ddc1d00 100644 --- a/app.py +++ b/app.py @@ -97,7 +97,6 @@ def ssh_process(ssh, input_ssh): stdin, stdout, stderr = ssh.exec_command(command_str) ssh_exit_status = stdout.channel.recv_exit_status() - print(f"ssh exit status: {ssh_exit_status}") out = "".join(stdout.readlines()) out = out.strip() if out is not None else None @@ -108,8 +107,7 @@ def ssh_process(ssh, input_ssh): err = err.strip() if err is not None else None if err: print(f"Error: \n{err}") - if out is None: - sys.exit(1) + if ssh_exit_status != 0: print(f"ssh exit status: {ssh_exit_status}") sys.exit(1)