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>
This commit is contained in:
Kairui Song 2021-08-04 17:15:42 +08:00
parent e4c7b5bbf5
commit d6449e7293
1 changed files with 7 additions and 8 deletions

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