Rclone check from within a script

So if you goal is to run a check from source to destination, you can just look for the return code of the check.

Here is an example of a check returning no changes and I made a small edit to the file so check returned a non zero return code.

felix@gemini:~$ rclone check /etc/hosts GD:
2019/01/17 16:12:25 NOTICE: Google drive root '': 0 differences found
felix@gemini:~$ echo $?
0
felix@gemini:~$ vi /etc/hosts
felix@gemini:~$ sudo vi /etc/hosts
felix@gemini:~$ rclone check /etc/hosts GD:
2019/01/17 16:12:46 ERROR : hosts: Sizes differ
2019/01/17 16:12:46 NOTICE: Google drive root '': 1 differences found
2019/01/17 16:12:46 Failed to check: 1 differences found
felix@gemini:~$ echo $?
1

So in your case, I’m assuming you would:

rclone check
if 0 do nothing
if 1
do this
do that
do this
do that

And that’s your workflow if I’m understanding.

1 Like

Yes sync will make the source equal to the destination and return an error only if that failed.

Animosity022, I tried to respond right after your last message but I was over the allowed number of messages for a new forum member. The message below is what I had intended to send:

Thanks, that is exactly what I am doing. This whole thread started with me asking if there was a code I could check, rather than parsing the log output. In a reply, calisro suggested that I check and see if the exit codes differed, depending on whether or not there have been changes. I determined that they do differ and updated my script.

The subsequent part of this thread sort of devolved into why I was using check instead of sync. For the most part it is because sync (actually I use copy) doesn’t change its exit code.

You could make a simple script eg

#!/bin/bash
Gdrive=/mnt/gdrive
LastRun="/home/plex/.cache/LastRun"
if [[ ! -f "$LastRun" ]]; then
    touch $LastRun
fi

find "$Gdrive" -mindepth 1 -type f -cnewer $LastRun |
while read Path; do
        echo "New/changed: $Path"
        # do whatever you want here with it
done
touch $LASTRUNFILE

Thanks Ajki. Unless I misunderstand, your script is checking to see when it was last run. That is different than my use case, check and see if any files are different on the remote. I have written a script, the conditional part looks like this (“FMA” is just the name of the product that the files comprise):

#!/bin/bash
...
# next check to see if FMA processing needs to be done
# if not, exit
$(rclone check FMATeamDrive: $LATEST_DIR)
check=$?
if [[ $check == 0 ]]; then
    echo "The FMA has NOT been modified "
else
    echo "The FMA has been modified"

    # since we are going to process the FMA, copy it down from Google Drive
    rclone copy FMATeamDrive: "$LATEST_DIR"

    # launch FMA processing script
    # ...
fi

Actually it makes lastrun to compare time date of that file and then process only files that changed on remote.
So you could sync/copy only changed files

Hi detwiler,

Thank you so much for the work you have done. This is what I want to do and you’re informative.

Hey dasfga,
My pleasure, glad I could help.
Cheers