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.

  • Swiggles@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    2
    arrow-down
    1
    ·
    edit-2
    1 year ago

    I know it is not really what is asked, but cron is a pain in the ass to handle and manage. I am not sure if it is officially deprecated yet, but I would migrate everything to systemd timers instead it is so much better. It provides configuration tools and proper integrated logging and troubleshooting tools.

    Just create a service file of type oneshot which runs your backup script and a timer unit with the same base name. Set the timer to hourly, place both files into /etc/systemd/system, do a daemon-reload and enable the timer. You can see the status or journal for output and list-timers to see the schedule and wether or not it ran.

    Usually if programs can run in a user context but don’t work as some automated process it is either due to environment differences. Most importantly PATH which can be solved by using absolute paths for programs. Another very common problem is the systems MAC implantation although it happens more often with SEL. Still you might want to check your AppArmor configuration and (audit) logs.

    If you want to stick with cron also make sure to read the mails (/var/mail/root by default), because most cron implementations dump their output/logs there.