On Fri, Sep 3, 2021 at 8:17 PM Philipp Rudo <prudo(a)redhat.com> wrote:
Hi Kairui,
On Thu, 19 Aug 2021 19:39:10 +0800
Kairui Song <kasong(a)redhat.com> wrote:
> 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.
>
> Signed-off-by: Kairui Song <kasong(a)redhat.com>
> ---
> mkdumprd | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/mkdumprd b/mkdumprd
> index 4707fd9b..de4e9944 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 ] && {
> + local _out
> +
> + if ! _out=$(ssh -q -n -i "$SSH_KEY_LOCATION" -o BatchMode=yes -o
StrictHostKeyChecking=yes "$1" "df -P $SAVE_PATH"); then
I would prefer to keep _opt. Without it the line is extremely long and hard to read.
OK, I'll make it an array then.
> perror_exit "checking remote ssh server available size failed."
> - }
> + fi
>
> #ssh output removed the line break, so print field NF-2
> - echo -n "$_out" | awk '{avail=NF-2; print $avail}'
> + echo -n "$_out" | tail -1 | awk '{avail=NF-2; print $avail}'
you could also get rid off the pipe to awk with df --output=avail instead
of -P. Unfortunately this still prints the header...
Same for get_fs_size
Good suggestion.
Thanks
Philipp
> }
>
> #mkdir if save path does not exist on ssh dump target
--
Best Regards,
Kairui Song