From 30495b995edb7f7bbb028c5c92341674aecc95d9 Mon Sep 17 00:00:00 2001 From: Andrew Engelbrecht Date: Mon, 18 Oct 2021 21:15:54 -0400 Subject: [PATCH] error message when ssh connection is interrupted Older, but fairly recent, versions of OpenSSH don't report a non-zero exit code if an SSH client process is killed with SIGTERM. This patch checks for a success or typical error message, otherwise it raises its own error. --- kaya | 12 +++++++++++- kaya-client | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/kaya b/kaya index 582f73c..c8f29f9 100755 --- a/kaya +++ b/kaya @@ -134,13 +134,23 @@ start-backup() { local password password="$(head -n1 "${password_file}")" + log_dump="$(mktemp)" + # make the backup over a forwarded port cat << EOF | ssh -R "${remote_port}:localhost:${local_port}" "${remote_user}@${hostname}" kaya-client \ - "${remote_port@Q}" "${hostname@Q}" "${backup_options[@]@Q}" + "${remote_port@Q}" "${hostname@Q}" "${backup_options[@]@Q}" \ + | tee "${log_dump}" | grep -v "KAYA_SUCCESSFUL_BACKUP_MESSAGE" ${kaya_protocol_version} ${password} EOF + # confirm that the SSH session completed + if tail -1 "${log_dump}" | grep -v -e "^KAYA_SUCCESSFUL_BACKUP_MESSAGE" -e "^kaya-client: command exit code" ; then + rm "${log_dump}" + echo "kaya: backup interrupted or failed to complete" >&2 + exit 1 + fi + rm "${log_dump}" } main() { diff --git a/kaya-client b/kaya-client index 83ec93f..1a82f9b 100755 --- a/kaya-client +++ b/kaya-client @@ -50,4 +50,7 @@ ret=0 if (( ret )); then echo "kaya-client: command exit code $ret: ${cmd[*]}" >&2 exit $ret +else + # needed in case ssh dies on the backup server, and exits with 0 (patched in OpenSSH version 8.8) + echo "KAYA_SUCCESSFUL_BACKUP_MESSAGE" fi -- 2.25.1