From d6449e7293fb426ebb9f0bffee57d675573a64d6 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 17:15:42 +0800 Subject: [PATCH] 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 --- mkdumprd | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mkdumprd b/mkdumprd index de0e22d..bc50208 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