this post was submitted on 17 Aug 2023
19 points (100.0% liked)
Linux
48655 readers
544 users here now
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
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).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.Too many numbers/stars
(The log part is optional)
As @[email protected] mentioned, you have too many time fields.
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.
Yes, you should never use sudo inside a users crontab. If you want to run as root then use the system crontab.
I would also encourage looking at systemd timers. They are more verbose then crontab, but far easier to debug and see what is going on. They work off services so automatically log to journald like all other services and you can easily see when they last ran, if it was successful and when it will next run with
systemctl list-timers
. All things you can do with cron, but requires a lot more setup yourself.I appreciate the advice! I had never really heard about the distinction between the system crontab and user crontabs. While it makes sense in retrospect, I am entirely self-taught about this stuff, and nowhere I had looked had ever mentioned that there were two separate crontabs.
Do you happen to know of a good resource to learn about those off the top of your head? I appreciate the suggestion!
The arch wiki is always a good place to look. There are a lot of introduction blog posts around that I have not read so cannot recommend - but plenty to look at if you need more information or a more beginner friendly guide than the arch wiki.
The freedesktop manuals are also worth a look at for more advanced stuff you can do with them - but are not really required for basic things. They just detail all the settings you have available and are much more of a reference than a guide.
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.