Can't get crontab to run backup script properly
Can't get crontab to run backup script properly
Hello everyone!
I'm running a few different services off of my Ubuntu VM on ProxMox, and they've all been running great for about 6 months now. However, I'm trying to setup some better backups and such of individual services, and I wrote a bash script to do that for me and delete older backups once I accumulate enough.
All of that works 100% fine. Like absolutely no issues with the script when I run it myself. However, I can not for the life of me get crontab to run it.
If I run sudo ./folder/directory/backup.sh
then everything runs perfectly. However, if I setup my crontab with 0 * * * * ./folder/directory/backup.sh
I get absolutely nothing.
I have also tried setting the crontab with sudo
, sh
, sudo sh
, and both combinations without the dot in front of the path to the shell script.
Does anyone have any idea what I am doing wrong?
Thank you so much for any help
Update: I have edited /etc/crontab
with the following 0 * * * * * root /mnt/nas/freshrss/backups/backup.sh
. After waiting for the crontab to fire off, nothing happened. Still not really sure what's going on.
The crontab has no concept of . meaning the current directory. Try with the full path to the script. You might also need a user (but you might not if it's a user's crontab as opposed to the system one).
So if those help and report back either way.
Not quite true.
.
exists in all directories so will work in any application. But it raises the question of what is the directory cron is running in. Probably not what you expect, definitely not your users home dir and you probably should not rely on it. So you should not use relative paths inside it - even if you can get them to work. Best to just stick to absolute paths or explicit cd to the right location before hand (that is on the same cron line or in the script it calls).I have edited
/etc/crontab
with the following0 * * * * * root /mnt/nas/freshrss/backups/backup.sh
. After waiting for the crontab to fire off, nothing happened.There's an extra *. There should be 5 time fields, but there's a zero followed by 5 *s. If that's not what's causing it, next spot I'd check is output from the cron logs. Not sure where that is in Ubuntu, though, might be in/var/log/messages or in the systemd journal. Cron sometimes sends mail when there's an error, too, so checking the users mail might give you some clues as well.
That's probably the issue, crontab has another workdir, so calling the script with a relative path won't work.
Just use the full path to the script, something like
/home/username/folder/directory/backup.sh
and it'll probably just work.So, right now I'm trying the system crontab instead of my user crontab.
Just to reiterate from my post, however, I have tried the full path. I was giving example paths. I should have been more explicit that by just "using dot" I meant using relative and absolute paths.
All paths have been full paths from the get go, though I did try cd-ing into the folder and running it with a relative path. My hope at this point is that it's somehow a permissions issue as my storage setup is a bit odd with TrueNAS Scale running as a VM on ProxMox. Permissions with docker are usually hell, and I have to run literally everything that touches my NAS as root to get the permissions to play nicely, so it would make sense here that it's just the permissions being upset and preventing access to the files.
I set a backup to run on the hour, so I'll report back with whatever happens.