0

First, sorry for the title, it's really difficult to resume my problem in a catch phrase.

I would like to build some bash script witch make a backup of a targeted directory, this backup will be in a server, using ssh. My strategy is using rsync, to make a save properly and this program support ssh connection.

BUT, the problem is, when I use rsync command in order to copy heavy datas it's take some times and during this time I want print a loader.

My question is : how can I print a loader during rsync process, and when the copy is terminated close the loader ? I tried to lauch rsync in background with & but I don't know how to communicate with this process.

My script :

#!/bin/bash

#Strat : launch in local machine rsync
#$1 contain the source file ex : cmd my_dir


function loader(){
    local i sp n
    sp[0]="."
    sp[1]=".."
    sp[2]="..."
    sp[3]=".."
    sp[4]="."

    for i in "${spin[@]}"
    do
    echo -ne "\b$i"
    sleep 0.1
    done
}


#main
if [ $# -ne 1 ]; then
    help #a function not detailed here
    exit 1
else
    if [ $1 = "-h" ]; then
    help
    else
    echo "==== SAVE PROGRAM ===="
    echo "connection in progress ..."
    sleep 1 #esthetic only
    
    #I launch the copy, it works fine. rsync is launch with non-verbose mode
    rsync -az $1"/" -e "ssh -p 22" serveradress:"SAVE/" &
    $w=$! #rsync previous command's pid

    #some code here to "wait" rsync processing, and during this time I would like to print some loading animation in my term (function loader).

    while [ #condition ??? ]
    do
        loader
    done

    wait $w
    
    echo "Copy complete !"
    fi
fi


Thank's for the help.

  • if you don't background rsync but instead run with a suitable `--info` option, you can read that output to decide when to close the loader – jhnc Apr 26 '21 at 22:49
  • rsync has a `--progress` option – pynexj Apr 27 '21 at 02:03
  • Thank's guys ! I'he already testes --progress but it's not good for my usage. But --info is good, on [this link](https://unix.stackexchange.com/questions/215271/understanding-the-output-of-info-progress2-from-rsync) have an interesting option : `--info=progress2` witch show something like this : `27,956,643 100% 1.84MB/s 0:00:14 (xfr#5, to-chk=0/6)` It's a pretty good solution, thank's :) – SieurTaurin Apr 27 '21 at 08:35

0 Answers0