This does much the same as Peter's answer, but gives the user the option of which remote file he wants, and where he wants to save it (as well as conducting the rsync over ssh). Replace the USER and HOST with your username and host respectively.
#!/bin/bash
echo -e "Please enter the full (escaped) file path:"
read -r path
echo "Path: $path"
echo -e "Enter the destination:"
read -r dst
echo "Destination: $dst"
while [ 1 ]
do
rsync --progress --partial --append -vz -e ssh "USER@HOST:$path" $dst
if [ "$?" = "0" ] ; then
echo "rsync completed normally"
exit
else
echo "rsync failure. Retrying in a minute..."
sleep 60
fi
done
The rsync options used here enable the progress stats during transfer, the saving of partial files upon unexpected failure, and the ability to append to partially completed files upon resume. The -v option increases verbosity, the -z option enables compression (good for a slow connection, but requires more cpu power on both ends), and the -e option enables us to conduct this transfer over ssh (encryption is always good).
Note: Use this only if you have public key login enabled with your ssh, otherwise it will ask you for a password when it restarts (killing all functionality of the script).
Possible duplicate of http://serverfault.com/q/98745.
– tanius – 2015-07-26T07:28:52.070Some useful info here - I just want to add that one way of getting round the repeated asking for password problem is to use the 'sshpass' command. Usually this needs to be installed with apt-get etc. – Rachael Saunders – 2017-10-02T09:30:08.253
Can't you check the return code?
while ./run_script; do echo "Retrying..."; done; echo "Done."
Make surerun_script
returns0
on success. – Kerrek SB – 2011-06-27T11:28:20.647