mkdumprd: fix multiple issues with get_ssh_size

upstream: fedora
resolves: bz2003832
conflict: none

commit d6449e7293
Author: Kairui Song <kasong@redhat.com>
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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
This commit is contained in:
Tao Liu 2021-11-03 15:36:02 +08:00
parent 0d42485888
commit 033d4cf5fb

View File

@ -94,15 +94,14 @@ to_mount() {
#$1=dump target #$1=dump target
#called from while loop and shouldn't read from stdin, so we're using "ssh -n" #called from while loop and shouldn't read from stdin, so we're using "ssh -n"
get_ssh_size() { get_ssh_size() {
local _opt _out local _out
_opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes" local _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."
}
#ssh output removed the line break, so print field NF-2 if ! _out=$(ssh -q -n "${_opt[@]}" "$1" "df" "--output=avail" "$SAVE_PATH"); then
echo -n "$_out" | awk '{avail=NF-2; print $avail}' 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 #mkdir if save path does not exist on ssh dump target