Rclone commands work from a terminal, but not from a bash script

Hi there, I got rclone working with dropbox and google drive on a raspberry pi last year sometime, but now it doesn’t seem to work properly with google drive. If i ssh into the pi, i can run the following command and it works.

rclone copyto GD_remote:/PVJclientMedia /media/internal/images --include ‘*.{jpg,JPG,bmp,BMP,png,PNG}’

Running the command with the “-vv” flag gave me the following output.

2019/04/02 18:50:27 DEBUG : rclone: Version “v1.40” starting with parameters [“rclone” “copyto” “GD_remote:/PVJclientMedia” “/media/internal/images” “–include” “*.{jpg,JPG,bmp,BMP,png,PNG}” “-vv”]
2019/04/02 18:50:27 DEBUG : Using config file from “/home/pi/.config/rclone/rclone.conf”
2019/04/02 18:50:28 INFO : Local file system at /media/internal/images: Modify window is 1ms
2019/04/02 18:50:29 INFO : Local file system at /media/internal/images: Waiting for checks to finish
2019/04/02 18:50:29 INFO : Local file system at /media/internal/images: Waiting for transfers to finish
2019/04/02 18:50:29 INFO : test.jpg: Copied (new)
2019/04/02 18:50:29 INFO :
Transferred: 890.547 kBytes (483.769 kBytes/s)
Errors: 0
Checks: 0
Transferred: 1
Elapsed time: 1.8s

2019/04/02 18:50:29 DEBUG : 4 go routines active
2019/04/02 18:50:29 DEBUG : rclone: Version “v1.40” finishing with parameters [“rclone” “copyto” “GD_remote:/PVJclientMedia” “/media/internal/images” “–include” “*.{pg,png,bmp,JPG,PNG,BMP}” “-vv”]

However, if I run the same command from the following bash script, nothing appears to happen.

#!/bin/bash

#kill all running tasks to get enough resources
/var/www/sync/stopall &

rclone copyto GD_remote:/PVJclientMedia /media/internal/images --include ‘*.{jpg,png,bmp,JPG,PNG,BMP}’

rclone copyto GD_remote:/PVJclientMedia /media/internal/video --include ‘*.{mp4,mov,MP4,MOV}’

rclone copyto GD_remote:/PVJclientMedia /media/internal/pdf --include ‘*.{pdf,PDF}’

rclone copyto GD_remote:/PVJclientMedia /media/internal/audio --include ‘*.{mp3,MP3}’

exit 0

my rclone config file is as follow :

[GD_remote]

type = drive

client_id =

client_secret =

scope = drive

root_folder_id =

service_account_file =

token = {“access_token”:“adfadf”,“token_type”:“Bearer”,“refresh_token”:“1adf”,“expiry”:"2019-04-0$

[DB_remote]

type = dropbox

client_id =

client_secret =

token = {“access_token”:“adf”,“token_type”:“bearer”,“expiry”:“0001-01-01T00:00:00Z”}

Any thoughts on why it won’t work from bash?

Thank you,

Sean

Try not to post your actual config keys as they give access to folks so I removed that from your post :slight_smile:

cron doesn’t have any environment variables or paths or anything like that so you need to use full paths in your scripts.

In my example, I use an environment variable to point to my config and you need the full path for rclone.

#!/bin/bash
# RClone Config file
RCLONE_CONFIG=/opt/rclone/rclone.conf
export RCLONE_CONFIG
LOCKFILE="/var/lock/`basename $0`"

(
  # Wait for lock for 5 seconds
  flock -x -w 5 200 || exit 1

# Move older local files to the cloud
/usr/bin/rclone move /data/local/ gcrypt: -P --checkers 3 --log-file /home/felix/logs/upload.log -v --transfers 3 --drive-chunk-size 32M --exclude-from /home/felix/scripts/excludes --delete-empty-src-dirs

) 200> ${LOCKFILE}

Hi there,

Thank you so much for your answer! Using the variable for the config file, like you suggested, made it work, which is great.

I do however, have one more question. Why does copying from dropbox not need that variable?

Before i made todays changes, the bash script to copy from google drive was almost identical to the one to copy from dropbox. The only difference was the name of the remote drive to connect to (google vs dropbox), yet DB worked and GD wouldn’t.

Thanks again, you’re awesome!! :smiley:

Can you share the script you have now? Easier to see an
d perhaps figure it out.

You can use the three ` to escape the script so it shows up like

this

Dropbox script


#kill all running tasks to get enough ressources
/var/www/sync/stopall &


rclone copyto DB_remote:/PVJclientMedia /media/internal/images --include '*.{jpg,png,bmp,JPG,PNG,BMP}'

rclone copyto DB_remote:/PVJclientMedia /media/internal/video --include '*.{mp4,mov,MP4,MOV}'

rclone copyto DB_remote:/PVJclientMedia /media/internal/pdf --include *.pdf

rclone copyto DB_remote:/PVJclientMedia /media/internal/audio --include *.mp3


exit 0

Google drive script


RCLONE_CONFIG=/home/pi/.config/rclone/rclone.conf
export RCLONE_CONFIG

#kill all running tasks to get enough ressources
/var/www/sync/stopall &


rclone copyto GD_remote:/PVJclientMedia /media/internal/images --include '*.{jpg,png,bmp,JPG,PNG,BMP}'

rclone copyto GD_remote:/PVJclientMedia /media/internal/video --include '*.{mp4,mov,MP4,MOV}'

rclone copyto GD_remote:/PVJclientMedia /media/internal/pdf --include '*.{pdf,PDF}'

rclone copyto GD_remote:/PVJclientMedia /media/internal/audio --include '*.{mp3,MP3}'


exit 0

Are you able to see the error when you run it?

The first line in a script usually points to a shell as well so something like:

#!/bin/bash
# RClone Config file
RCLONE_CONFIG=/opt/rclone/rclone.conf
export RCLONE_CONFIG
LOCKFILE="/tmp/`basename $0`"

# Move older local files to the cloud
/usr/bin/rclone move /data/local/ gcrypt: -P --checkers 3 --log-file /opt/rclone/logs/upload.log -v --tpslimit 3 --transfers 3 --drive-chunk-size 32M --exclude-from /opt/rclone/scripts/excludes --delete-empty-src-dirs

I always put full paths as well to be safe.

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