Rclone script problem when run as a cron job


#1

hi guys
i am using a script to create daily backups of a folder + sql file on a server running centos using rclone that uploads to azure.

this script works fine when I run it via ssh console, but if I add it as cron job in /etc/crontab, the script runs, creates the dump.sql, puts the archive in tmp folder, but does not upload it to azure. i am guessing it fails at the rclone part.

here is the script,what is the problem here, can someone tell me>?
https://hastebin.com/udehehamap.bash


#2

What user is the crontab running as - the same as you tested rclone with?


#3

Yes, as root.

This is what my /etc/crontab file looks like
https://hastebin.com/nirarofudi.shell


#4

What do the logs say?

The usual problem people have with rclone in crontabs is it not being able to find its config file, so you can try adding the --config /path/to/config directive. Use rclone config file to show where it is.


#5

Ran the ‘rclone config’ command

Here is the output

rclone config
2018/12/05 17:26:54 NOTICE: Config file “/root/.config/rclone/rclone.conf” not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config


#6

The script runs without a config file set because we mention variables in the script itself. Are you saying we should add a config for the remote destination?


#7

Sorry, missed that bit in your script. You don’t need a config file in that case.

What do the logs say from the cronjob? They will have a clue in I would have thought.


#8

the logs are empty.
If you see the script above, its actually doing so:

  1. making sql dump
  2. adding a folder to backup in archive + the sql dump made above
  3. uploading file to rclone
  4. deleting it locally

the error comes on part number 3 (uploading to rclone), if i run this script as cron.
this is because the .tar files keep accumulating in /tmp folder but are not uploaded to azure when I put on the cron.

if i run the same script via ssh terminal as ‘sh scriptfile.sh’, then there are no problems.

please help me.


#9

What’s the full command you are running and the actual error message?

running from cron usually means you are missing a parameter or something you have set that isn’t being set in cron as it doesn’t read in your profile.


#10

how do I add bash code in my reply on this forum? i can only find quote preformatting


#11

You can put the 's before and after it.

So like

here

#12
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
@hourly root sh /rclone.sh > /output-crontab.log

This is the command I am using in /etc/crontab for cron.


#13

What’s in the rclone.sh and what’s the error?