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.