Page 1 of 1

[Solved] cron.daily scripts not running

Posted: Mon Jun 18, 2018 2:34 pm
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

Re: cron.daily scripts not running

Posted: Mon Jun 18, 2018 3:43 pm
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.

Re: cron.daily scripts not running

Posted: Mon Jun 18, 2018 3:52 pm
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.

Re: cron.daily scripts not running

Posted: Mon Jun 18, 2018 4:07 pm
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

Re: cron.daily scripts not running

Posted: Mon Jun 18, 2018 4:11 pm
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.

Re: [Solved] cron.daily scripts not running

Posted: Mon Jun 18, 2018 4:13 pm
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