Restart rsync on failure via shell script

From Notes_Wiki
Revision as of 05:08, 19 May 2022 by Saurabh (talk | contribs) (Created page with "Home > Shell scripting > Useful bash shell scripts > Restart rsync on failure via shell script It is possible to create shell script to restart rsync, if it exits with failure status (non-zero return value) using: <pre> #!/bin/bash while [ 1 ] do <rsync-command> if [ "$?" = "0" ] ; then echo "rsync completed normally" exit else echo "Rsync failed. Retrying..." sleep 180 fi done </pre> Here replac...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Home > Shell scripting > Useful bash shell scripts > Restart rsync on failure via shell script

It is possible to create shell script to restart rsync, if it exits with failure status (non-zero return value) using:

#!/bin/bash

while [ 1 ]
do
    <rsync-command>
    if [ "$?" = "0" ] ; then
        echo "rsync completed normally"
        exit
    else
        echo "Rsync failed. Retrying..."
        sleep 180
    fi
done

Here replace <rsync-command> with appropriate rsync (or any other shell command that needs to be retried and ends with 0 status on success, non-zero on failure.


Refer:


Home > Shell scripting > Useful bash shell scripts > Restart rsync on failure via shell script