From 033d4cf5fbc741cb548ac166b3e5d27c3b107421 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Wed, 3 Nov 2021 15:36:02 +0800 Subject: [PATCH] mkdumprd: fix multiple issues with get_ssh_size upstream: fedora resolves: bz2003832 conflict: none commit d6449e7293fb426ebb9f0bffee57d675573a64d6 Author: Kairui Song Date: Wed Aug 4 17:15:42 2021 +0800 mkdumprd: fix multiple issues with get_ssh_size Currently get_ssh_size is not working as expected, it should return the target's available space, but it will include df's header row string as the result. Fix this issue by only use the last output line. And the _opt variable will be used as args so it should be an array. Also remove the awk call, just use `df --output=avail` instead. Signed-off-by: Kairui Song Acked-by: Philipp Rudo Signed-off-by: Tao Liu --- mkdumprd | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mkdumprd b/mkdumprd index d062a91..1113e7c 100644 --- a/mkdumprd +++ b/mkdumprd @@ -94,15 +94,14 @@ to_mount() { #$1=dump target #called from while loop and shouldn't read from stdin, so we're using "ssh -n" get_ssh_size() { - local _opt _out - _opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes" - _out=$(ssh -q -n $_opt $1 "df -P $SAVE_PATH") - [ $? -ne 0 ] && { - perror_exit "checking remote ssh server available size failed." - } + local _out + local _opt=("-i" "$SSH_KEY_LOCATION" "-o" "BatchMode=yes" "-o" "StrictHostKeyChecking=yes") - #ssh output removed the line break, so print field NF-2 - echo -n "$_out" | awk '{avail=NF-2; print $avail}' + if ! _out=$(ssh -q -n "${_opt[@]}" "$1" "df" "--output=avail" "$SAVE_PATH"); then + perror_exit "checking remote ssh server available size failed." + fi + + echo -n "$_out" | tail -1 } #mkdir if save path does not exist on ssh dump target