Any logic to verify rclone command was successful before running another rclone command?

Is there any logic that rclone can use?

For example I need to rclone copy a local file to a remote destination, and then I need to rclone move the local file a different local destination, BUT I only want to do the move if the inital copy was successful.

I think this falls within "general coding" moreso than rclone-spesific.
As such you may get more appropriate help on "stack overflow".

My best intuition tells me you would need to determine the success of the copy command based on the exit-code of the script - and then make an appropriate determination based on that. The exit -code will depend on whether the previous command was a success (typically "0") or a some kind of failure.
So you might want to check "was exit code anything other than "0"? if so re-try until exit code is "0" before proceeding". Something along those lines.

Do note that rclone move will never delete files if they weren't successfully transferred, so it should never result in the loss of data.

Here is an example snippet in batch (windows):

::If exit code of above command was anything but normal, display an error and pause

if not %ERRORLEVEL% equ 0 (
	echo Something went wrong during precaching. Check mount is running. Press any key to continue.
) else (
	echo Cache warmup for %mountpath% OK!

(from my personal rclone precaching script).

1 Like

Oh yes that makes sense... and I am using a Windows batch file to run the command, so this is perfect.


No problem - then it should be fairly easy to adapt the example to your needs.

Just be ware that under Windows (CMD) the error-code variable will contain the exit-code of whatever command you ran last (where applicable).
So it is best to run the exit-code test immediately after the thing you are checking to avoid something else "polluting" the result.

Exactly what exit-codes rclone gives for various failures is something I do not have memorized. If you need to know this it should be available either in the documentation (99% sure) or in the worst-case the open source-code. If you get hopelessly lost, ask @ncw to point you towards where the information can be found. :slight_smile:


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.