I want to rsync files from one server to another server every 5 minutes, but only want to start the rsync if the previous rsync command has finished. Time for one rsync depends on how much data changed on the source server, so the time taken to finish rsync cronjob varies.

Create file rsync.sh


if ! pgrep -x "rsync" > /dev/null
    rsync -avzP /var/www/html/files/  [email protected]:/var/www/html/files/

Set cronjob like

*/10 * * * * /root/rsync.sh > /dev/null