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.

  • theRealBassist@lemmy.worldOP
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    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.

    • nous@programming.dev
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 year ago

      So, right now I’m trying the system crontab instead of my user crontab.

      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.

      • theRealBassist@lemmy.worldOP
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        Yes, you should never use sudo inside a users crontab. If you want to run as root then use the system crontab.

        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.

        I would also encourage looking at systemd timers

        Do you happen to know of a good resource to learn about those off the top of your head? I appreciate the suggestion!

        • nous@programming.dev
          link
          fedilink
          English
          arrow-up
          2
          ·
          1 year ago

          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.