You are not logged in.

#1 2026-03-20 12:38:31

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 386
Website

[SOLVED]need help with a daily cron job not executing or getting error

This might be pretty simple to figure out but no matter what I have tried it doesn't work.
The script is in the /etc/cron.daily folder
if I execute the file from the $prompt evern with sudo I get a permissions error.
If I change to root with the # prompt the script runs perfectly.

I will show you the contents of the directories and let me know what else you need.
I am testing by running this command:

sudo run-parts /etc/cron.daily/
demo@mail cron.daily]$ ls -l
total 4
-rwxr-xr-x 1 root root 592 Mar 20 07:59 mailcow-backup.sh
[demo@mail cron.d]$ ls -l
total 8
-rw-r--r-- 1 root root 158 Mar 20 08:26 0daily
-rw-r--r-- 1 root root 128 Sep 22 04:05 0hourly
# Run the daily jobs
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=danc@dccathome.com
0 1 * * * root run-parts /etc/cron.daily./mailcow-backup.sh
#!/bin/bash

# Backup mailcow data
# https://docs.mailcow.email/backup_restore/b_n_r-backup/

set -e

OUT="$(mktemp)"
export MAILCOW_BACKUP_LOCATION="/mnt/mailbackup"
SCRIPT="/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh"
PARAMETERS="backup all"
OPTIONS="--delete-days 3"

# run command
set +e
"${SCRIPT}" ${PARAMETERS} ${OPTIONS} 2>&1 > "$OUT"
RESULT=$?

if [ $RESULT -ne 0 ]
    then
            echo "${SCRIPT} ${PARAMETERS} ${OPTIONS} encounters an error:"
            echo "RESULT=$RESULT"
            echo "STDOUT / STDERR:"
            cat "$OUT"
fi

Last edited by MAYBL8 (2026-03-20 15:37:21)

Online

#2 2026-03-20 12:50:57

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 577

Re: [SOLVED]need help with a daily cron job not executing or getting error

MAYBL8 wrote:
0 1 * * * root run-parts /etc/cron.daily./mailcow-backup.sh

Is there a dot at the end of /etc/cron.daily./ ?

MAYBL8 wrote:

if I execute the file from the $prompt evern with sudo I get a permissions error.
If I change to root with the # prompt the script runs perfectly.

What are "the $prompt" and "the # prompt"?
What are exact commands and error messages?
Add "set -x" to the script to trace execution.

Offline

#3 2026-03-20 12:57:57

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 386
Website

Re: [SOLVED]need help with a daily cron job not executing or getting error

dimich wrote:
MAYBL8 wrote:
0 1 * * * root run-parts /etc/cron.daily./mailcow-backup.sh

Is there a dot at the end of /etc/cron.daily./ ?
yes

MAYBL8 wrote:

if I execute the file from the $prompt evern with sudo I get a permissions error.
If I change to root with the # prompt the script runs perfectly.

What are "the $prompt" and "the # prompt"?
like $sudo ./mailcow-backup.sh
vs $./mailcow-backup.sh
What are exact commands and error messages?

[demo@mail cron.daily]$ ./mailcow-backup.sh
/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh: line 79: /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/../mailcow.conf: Permission denied
/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh backup all --delete-days 3 encounters an error:
RESULT=1
STDOUT / STDERR:
Using 1 Thread(s) for this run.
Notice: You can set the Thread count with the THREADS Variable before you run this script.
Using /mnt/mailbackup as backup/restore location.

Could not determine compose project name

Add "set -x" to the script to trace execution.

[demo@mail cron.daily]$ ./mailcow-backup.sh
++ mktemp
+ OUT=/tmp/tmp.iVTeqxS2kn
+ export MAILCOW_BACKUP_LOCATION=/mnt/mailbackup
+ MAILCOW_BACKUP_LOCATION=/mnt/mailbackup
+ SCRIPT=/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh
+ PARAMETERS='backup all'
+ OPTIONS='--delete-days 3'
+ set +e
+ /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh backup all --delete-days 3
/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh: line 79: /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/../mailcow.conf: Permission denied
+ RESULT=1
+ '[' 1 -ne 0 ']'
+ echo '/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh backup all --delete-days 3 encounters an error:'
/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh backup all --delete-days 3 encounters an error:
+ echo RESULT=1
RESULT=1
+ echo 'STDOUT / STDERR:'
STDOUT / STDERR:
+ cat /tmp/tmp.iVTeqxS2kn
Using 1 Thread(s) for this run.
Notice: You can set the Thread count with the THREADS Variable before you run this script.
Using /mnt/mailbackup as backup/restore location.

Could not determine compose project name
[demo@mail cron.daily]$

Last edited by MAYBL8 (2026-03-20 13:00:47)

Online

#4 2026-03-20 13:20:38

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 577

Re: [SOLVED]need help with a daily cron job not executing or getting error

MAYBL8 wrote:
dimich wrote:

Is there a dot at the end of /etc/cron.daily./ ?
yes

Why? "cron.daily" and "cron.daily." are different paths. The latter is incorrect for cron.

MAYBL8 wrote:
/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh: line 79: /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/../mailcow.conf: Permission denied

What backup_and_restore.sh is trying to do with mailcow.conf at line 79? Read it, write or execute? The problem is accessing mailcow.conf.

Offline

#5 2026-03-20 13:39:58

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 386
Website

Re: [SOLVED]need help with a daily cron job not executing or getting error

I'm sorry I am not understanding any of your questions.
I changed the cron line to this but it still didn't run.

0 1 * * * root run-parts /etc/cron.daily/./mailcow-backup.sh

This is what it says at line 79

source ${SCRIPT_DIR}/../mailcow.conf

Just to be clear if I run the script from the directory  /etc/cron.daily
it runs with
sudo ./mailcow-backup.sh
and
if I change to root
it runs by just using ./mailcow-backup.sh

running this command it does not work

sudo run-parts /etc/cron.daily

Online

#6 2026-03-20 14:02:45

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 577

Re: [SOLVED]need help with a daily cron job not executing or getting error

MAYBL8 wrote:
0 1 * * * root run-parts /etc/cron.daily/./mailcow-backup.sh

You can write just

0 1 * * * root run-parts /etc/cron.daily/mailcow-backup.sh

This is not the reason why the script fails but "cron.daily./" is incorrect and "cron.daily/./" is redundant here.

UPD: Wait, this is also incorrect. run-parts expects directory name, not an executable. It should be

0 1 * * * root /etc/cron.daily/mailcow-backup.sh
MAYBL8 wrote:
demo@mail cron.daily]$ ./mailcow-backup.sh
...
/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh: line 79: /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/../mailcow.conf: Permission denied

Here you run mailcow-backup.sh as user. Most likely the user has no access permissions to mailcow.conf, so it fails, as expected.

MAYBL8 wrote:

running this command it does not work

sudo run-parts /etc/cron.daily

Does not work how? Show output of

sudo run-parts --debug --verbose /etc/cron.daily

Last edited by dimich (2026-03-20 14:28:01)

Offline

#7 2026-03-20 14:22:23

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 386
Website

Re: [SOLVED]need help with a daily cron job not executing or getting error

ok i removed the ./

here is the result of running the command you asked.

demo@mail cron.daily]$ sudo run-parts --debug --verbose /etc/cron.daily
"mailcow-backup.sh": classicalre fail

Online

#8 2026-03-20 14:40:00

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 577

Re: [SOLVED]need help with a daily cron job not executing or getting error

MAYBL8 wrote:

"mailcow-backup.sh": classicalre fail

man 8 run-parts:

If neither the --lsbsysinit option nor the --regex option is given then the names must consist entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens.

"mailcow-backup.sh" is not valid name for run-parts.

Also take a look to my previous comment update. "run-parts /etc/cron.daily/mailcow-backup.sh" is also incorrect. run-parts expects directory, not an executable.

Offline

#9 2026-03-20 14:49:55

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 386
Website

Re: [SOLVED]need help with a daily cron job not executing or getting error

I changed the filename and I removed the /mailcow-backup.sh from the 0daily entry.

0 1 * * * root run-parts /etc/cron.daily

still get an error:

[demo@mail cron.daily]$ sudo run-parts --debug --verbose /etc/cron.daily
"mailcowbackup.sh": classicalre fail

Online

#10 2026-03-20 15:22:43

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 74,661

Re: [SOLVED]need help with a daily cron job not executing or getting error

entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens

In which of those categories falls "."?
Why are you trying to use run-parts itfp?

Offline

#11 2026-03-20 15:33:14

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 386
Website

Re: [SOLVED]need help with a daily cron job not executing or getting error

seth wrote:

entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens

In which of those categories falls "."?
Why are you trying to use run-parts itfp?

so to run the script doesn't it need to be a .sh file?
How do I run the script without it being a .sh file?

I thought that is how the line was supposed to look and run.

What commands do I use?

Edit:
I took out the .sh and it ran.
I will mark this solved.
Thanks

Last edited by MAYBL8 (2026-03-20 15:36:14)

Online

#12 2026-03-20 15:35:17

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 74,661

Re: [SOLVED]need help with a daily cron job not executing or getting error

The script needs to be executable and head w/ a shebang ("#!/bin/sh") and then you can call it whatever you want.

What commands do I use?

dimich wrote:
0 1 * * * root /etc/cron.daily/mailcow-backup.sh

Offline

#13 2026-03-21 12:47:13

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 386
Website

Re: [SOLVED]need help with a daily cron job not executing or getting error

Now that I have it working  It is working too well.
For some reason it created to backups
One at 1:00am
And one at 3:46 am for some reason.

Last edited by MAYBL8 (2026-03-21 12:47:46)

Online

#14 2026-03-21 12:55:27

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 74,661

Re: [SOLVED]need help with a daily cron job not executing or getting error

Does the script actually get called at those times?

#!/bin/bash

# Backup mailcow data
# https://docs.mailcow.email/backup_restore/b_n_r-backup/

date >> /tmp/mailcow.calls

…

Does the system sleep or hibernate or so between 01:00 and 03:46 ?

Offline

#15 2026-03-21 13:17:11

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 386
Website

Re: [SOLVED]need help with a daily cron job not executing or getting error

the actual script looks pretty complicated to me so I don't want to get into that right now.
I don't have anything running that i am aware of that would put the machine to sleep.

Tell you what let me see what happens tomorrow and then I will see if it does the same thing.

Online

#16 2026-03-21 15:44:55

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 577

Re: [SOLVED]need help with a daily cron job not executing or getting error

MAYBL8 wrote:

It is working too well.

You should EITHER put the script to /etc/cron.daily/
In this case it will run by

0 1 * * * root run-parts /etc/cron.daily

from /etc/cron.d/0daily

OR put

0 1 * * * root /path/to/mailcow-backup

to /etc/cron.d/0daily or whatever other crontab. In this case the script should be NOT in /etc/cron.daily/ to prevent running by "run-parts /etc/cron.daily".

As alternative, you can use systemd timer.

Offline

#17 2026-03-21 17:45:16

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 386
Website

Re: [SOLVED]need help with a daily cron job not executing or getting error

If I understood this correctly.
I removed /etc/cron.d/0daily

and in the directory /etc/cron.daily is this:

[demo@mail cron.daily]$ ls
mailcowbackup

Online

#18 2026-03-21 19:30:11

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 577

Re: [SOLVED]need help with a daily cron job not executing or getting error

MAYBL8 wrote:

I removed /etc/cron.d/0daily and in the directory /etc/cron.daily is this: mailcowbackup

No. If you removed /etc/cron.d/0daily, nothing will run scripts from /etc/cron.daily/. (Unless you manually add "0 1 * * * root run-parts /etc/cron.daily" to some crontab).

If there is a line "0 1 * * * root run-parts /etc/cron.daily" in 0daily, it executes "run-parts /etc/cron.daily" daily. "run-parts" executes scripts from /etc/cron.daily.
If there is a line "0 1 * * * root /path/to/mailcowbackup" in 0daily, it executes "/path/to/mailcowbackup" daily.
If there are both lines in 0daily, and mailcowbackup is in /etc/cron.daily/, it executes mailcowbackup twice: via run-parts and as a separate cronjob.
If 0daily doesn't exist or doesn't contain corresponding entries, mailcowbackup is never executed no matter where it is located.

Last edited by dimich (2026-03-21 19:33:07)

Offline

#19 2026-03-21 21:53:32

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 386
Website

Re: [SOLVED]need help with a daily cron job not executing or getting error

Ok I am sorry for being so dense.
I have recreate a 0daily
and put
0 1 * * * root run-parts /etc/cron.daily
in it

The script is in the cron.daily  directory

Last edited by MAYBL8 (2026-03-21 21:54:18)

Online

#20 2026-03-21 22:07:15

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 577

Re: [SOLVED]need help with a daily cron job not executing or getting error

Yep, this should work.
crond looks for files /etc/cron.d/, finds 0daily, reads it and schedules "run-parts /etc/cron.daily" to execute as root every day at 1:00.
When executed, run-parts looks for files in /etc/cron.daily/ directory, finds your script and executes it.

Offline

#21 2026-03-22 12:10:18

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 386
Website

Re: [SOLVED]need help with a daily cron job not executing or getting error

For some reason it made 2 backups again.
one at 1
and one at 3:38 this time.

How can I troubleshoot this?
thanks

OK I looked at journalctl -b and found this at 3:46

Mar 21 03:46:00 mail anacron[766432]: Job `cron.daily' started

That matches the time from yesterday

Ok I found this in the anacrontab file:

I commented out the line for cron.daily

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=danc@dccathome.com
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22

#period in days   delay in minutes   job-identifier   command
#1      5       cron.daily              nice run-parts /etc/cron.daily
7       25      cron.weekly             nice run-parts /etc/cron.weekly
@monthly 45     cron.monthly            nice run-parts /etc/cron.monthly

Should this be the solution?

Last edited by MAYBL8 (2026-03-22 12:52:28)

Online

#22 2026-03-22 13:58:40

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 577

Re: [SOLVED]need help with a daily cron job not executing or getting error

MAYBL8 wrote:

Should this be the solution?

It depends on what you want to achieve.
If you want to run a job at specific time periodically, you should use cron.
If you want to run a job at random time but not more frequently than specific period, you should use anacron.

Offline

#23 2026-03-22 15:14:50

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 577

Re: [SOLVED]need help with a daily cron job not executing or getting error

Indeed, there is some confusion because different cron implementations may use different schemas to run asynchronous jobs. Assuming you use cronie.

If exact time of execution doesn't matter, place mailcowbackup script to /etc/cron.daily/. With your /etc/anacrontab it will run between 3:00 and 22:00 with random 5..50 minute delay according to this line:

1       5       cron.daily              nice run-parts /etc/cron.daily

If you comment this line, neither mailcowbackup nor other scripts in /etc/cron.daily will run by anacron. I would not recommend to comment it.
"/etc/cron.d/0daily" can be removed.

If you want to run mailcowbackup at exact time, you should place mailcowbackup somewhere else and configure cron to run it. For example, in /etc/cron.d/0daily:

0 1 * * * root /usr/local/lib/backup-scripts/mailcowbackup

(Actualy the name of file in /etc/cron.d/ can be any, not necessary "0daily". E.g. /etc/cron.d/backups).

Offline

Board footer

Powered by FluxBB