Rclone script won’t run in crontab

Hi!
I want to synchronize photos taken on Raspberry Pi to Google Drive.
The capture_photo.sh script works automatically using crontab, but the rclone.sh script, which should upload the photo to google drive, only works if I run it terminal(not when crontab is running).

[capture_photo.sh]
#!/bin/bash
for ((i=1; i<=10; i++))
do
timestamp=$(data +%y%m%d_%H%M%S)
filename="/home/pi/Farm/p_$timestamp.jpg"
sudo libcamera-still --immediate -o $filename
sleep 2
done

[rclone.sh]
#!/bin/sh
/usr/bin/rclone copy "/home/pi/Farm" "sfpj:/sf" &

[sudo crontab -e]
0 10 * * * /home/pi/capture_photo.sh
2 10 * * * /home/pi/rclone.sh > /home/pi/cron.log 2>&1

It was originally
pi@raspberrypi:~ $ rclone config file
Configuration file is stored at:
/home/pi/.config/rclone/rclone.conf
, but I changed it to
pi@raspberrypi:~ $ rclone config file
Configuration file is stored at:
/opt/rclone/rclone.conf
using
sudo mkdir -p /opt/rclone(Because there was no "/opt/rclone" file.)
sudo mv /home/pi/.config/rclone/rclone.conf /opt/rclone/rclone.conf
.
And
export RCLONE_CONFIG=/opt/rclone/rclone.conf
did.

Then, when I run crontab, an error(Failed to load config file "/opt/rclone/rclone.conf": open /opt/rclone/rclone.conf: permission denied) appears.

Is it wrong to change it like that?
Since I did it like that, nothing worked as it should have... What should i do?
(I am a beginner and a student. I would appreciate it if you could provide as much detail as possible.)

It is not really rclone problem but basic Linux permissions issues.

include log file in debug mode and it will tell you what the problem is.

How do I do that?

Actually you have your answer already above. Adjust permissions so your crontab user can access this file.

If not sure what you are doing then I recommend you do not change files locations.

Permission to access files? How do that? Using chmod?

And if i don't change files locations, do I have to proceed with /home/pi/~ as is it?

Yes you can use chmod.

The key is - wherever you put your file make sure that user your rclone runs under crontab has access to it.

What was the reason you moved it to /opt?

Can I use
chmod -x /opt/rclone/rclone.conf
(or in original chmod -x /home/pi/.config/rclone/rclone.conf)
?

I search for related this problems and tried because there was a way like that.

You have root access to your system and you use it so you should learn what you are doing. There is no other way.

umm I still don't know how to solve it... Can you tell me how to do it directly with an example?

Unfortunately, I have to do it by tomorrow.. So I'm in a hurry.

Can you explain why you decided to move it to /opt folder?

You can move any files anywhere really - but if you are doing it you should understand some basics I am afraid. If not just do not.

There's no big reason. I search google to solve the problem, and I saw a comment that was written like that on a similar problem to mine. So I tried it.
If I don't have to do it like that, don't have to move it.

(i would appreciate it if you could continue to help me.)

For consistenacy change:

[rclone.sh]
#!/bin/sh

To

[rclone.sh]
#!/bin/bash

Also, in crontab try

0 10 * * * /home/pi/capture_photo.sh >/dev/null 2>&1
2 10 * * * /home/pi/rclone.sh > /home/pi/cron.log

Specifiy your config file. Remember crontab you have setup as root not user. Add

--config=/path/to/rclone.conf

To the script. e.g. rclone copy /dir remote: --config=/etc/etc/

if you do not want to do that, change user in crontab:

2 10 * * * pi /home/pi/rclone.sh > /home/pi/cron.log 2>&1

Report back

Thanks.

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