[Solved] cron.daily scripts not running

Having issues with your DietPi installation, or, found a bug? Post it here.
Post Reply
unixmit
Posts: 45
Joined: Wed Jun 13, 2018 7:37 pm

[Solved] cron.daily scripts not running

Post by unixmit »

Am i right in thinking that If i put a script in /etc/cron.daily then it will be run once a day? Is there anything else I need to do to enable this because i have 2 scripts in there (user:group set to root and chmod +x on both) but neither of them run. I tried moving them to /etc/cron.minutely with no joy either.

Am I missing a step?

Thanks
User avatar
MichaIng
Site Admin
Posts: 2334
Joined: Sat Nov 18, 2017 6:21 pm

Re: cron.daily scripts not running

Post by MichaIng »

Please verify, that your scripts do not contain any syntax error and contain #!/bin/bash as first line and the result is as expected.

Code: Select all

bash /etc/cron.daily/your_script
Cron calls the scripts via run-parts command, you can also check that your scripts are handled by this, by checking if the following output contains them:

Code: Select all

run-parts --test /etc/cron.daily
Finally, if this works, but cron does still not execute them, verify that /etc/crontab actually contains the needed line and is not broken somehow:
cat /etc/crontab
Result should be (with possible adjusted times via dietpi-cron):

Code: Select all

root@DietPi:~# cat /etc/crontab
#Please use dietpi-cron to change cron start times
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
*/15 * * * *   root    cd / && run-parts --report /etc/cron.minutely
17 * * * *   root    cd / && run-parts --report /etc/cron.hourly
25 1 * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 1 * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 1 1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
dietpi-cron can be used to adjust times and regenerate/fix /etc/crontab in case.
unixmit
Posts: 45
Joined: Wed Jun 13, 2018 7:37 pm

Re: cron.daily scripts not running

Post by unixmit »

Thanks so much for your help.

The scripts are fine and run correctly with:

Code: Select all

bash /etc/cron.daily/mikrotik-clean.sh
Running the command below, as you suggested, doesn't show my scripts in the output. Any idea why this could be?

Code: Select all

run-parts --test /etc/cron.daily
Also /etc/crontab contains the needed lines.

Thanks for your help.
unixmit
Posts: 45
Joined: Wed Jun 13, 2018 7:37 pm

Re: cron.daily scripts not running

Post by unixmit »

OK I know where the issue is. Thanks for the guidance MichaIng, it helped.

What I didn't realise was that run-parts doesn't like periods. My scripts had the extension .sh Once I removed that all was fine.

Thank you
User avatar
MichaIng
Site Admin
Posts: 2334
Joined: Sat Nov 18, 2017 6:21 pm

Re: cron.daily scripts not running

Post by MichaIng »

Ah great and good to know, would have been my last guess, based on the fact that non of the other scripts contain file endings.
unixmit
Posts: 45
Joined: Wed Jun 13, 2018 7:37 pm

Re: [Solved] cron.daily scripts not running

Post by unixmit »

Because you mentione run-parts I did some investigating and found this which made me realise:
https://askubuntu.com/questions/611336/ ... ot-working

Thanks again
Post Reply