How to automate Rclone move with a bash script?

What is the problem you are having with rclone?

Need help in writing a crontab bash script that runs after 30min in a loop, and in this script actually I would want to execute a rclone move command that moves all the sub-directories of a particular directory to a remote.
(e.g.) there is a directory documents and it has sub-directories; user1, user2, user3, user4 ..., I would want to move all these directories inside documents parent directory to the remote but not have itself deleted.

Run the command 'rclone version' and share the full output of the command.

rclone v1.58.1

  • os/version: ubuntu 22.04 (64 bit)
  • os/kernel: 5.15.0-1011-oracle (aarch64)
  • os/type: linux
  • os/arch: arm64
  • go/version: go1.17.9
  • go/linking: static
  • go/tags: none

Are you on the latest version of rclone? You can validate by checking the version listed here: Rclone downloads
--> YES

Which cloud storage system are you using? (eg Google Drive)

Microsoft OneDrive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

```rclone move /home/dexter/downloads/documents teamdrive: -P --tpslimit 9 --fast-list --delete-empty-src-dirs

The rclone config contents with secrets removed.

```Name                 Type
====                     ====
onedrive             onedrive

hello and welcome to the forum,

there are a number of post about cron in the forum,
https://forum.rclone.org/t/problems-with-cron-job/28375
https://forum.rclone.org/t/trouble-executing-rclone-in-crontab/22943
https://forum.rclone.org/t/backup-script-best-practices/31023

Assuming your rclone command is doing what you want and you only need help with the bash script.
Super easy. Create a file, im going to use nano because i find it easiest.

nano rclonemove.sh

#!/bin/bash
rclone move /home/dexter/downloads/documents teamdrive: -P --tpslimit 9 --fast-list --delete-empty-src-dirs

ctrl+x to quit, y to save.

we now need to make it executable.

chmod +x rclonemove.sh

and finally to add it to your crontab for every 30 mins (this site is useful for trying different time syntaxes https://crontab.guru/)

crontab -e

*/30 * * * * /full/path/to/you/script/rclonemove.sh

assuming this is also nano, ctrl+x then y.

There you go, crontab will run that script every 30 mins. The script is literally just your command of choice.

theres some extra stuff you may want to look into. such as having it output to a log. or if you want to get real fancy, using supervisor to run the script in a loop continuously instead of every 30 mins. ill leave that up to you to research how to use.

1 Like

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