/etc/cron.d Jobs not running every minute

Creating a bug report/issue

Required Information

  • DietPi version | cat /boot/dietpi/.version 8.19.1 (master, owner: MichaIng, G_LIVE_PATCH_STATUS=[applied,applied,not applied]
  • Distro version | echo $G_DISTRO_NAME $G_RASPBIAN bookworm 0
  • Kernel version | uname -a Linux DietPi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux
  • Architecture | dpkg --print-architecture arm64
  • SBC model | echo $G_HW_MODEL_NAME or (EG: RPi3) RPi 3 Model B+ (aarch64)
  • Power supply used | (EG: 5V 1A RAVpower) 5V DC 3A
  • SD card used | (EG: SanDisk ultra) SanDisk Extreme 32GB

Steps to reproduce

I just have a bunch of test files in /etc/cron.d/

root@DietPi:/# for f in $(find /etc/cron.d -name 'test*.sh') ; do echo ==========; echo $f; echo $(ls -la $f); echo ----------; echo $(cat $f); done
==========
/etc/cron.d/test.sh
-rw-r--r-- 1 root root 88 Jul 22 18:05 /etc/cron.d/test.sh
----------
*/1 * * * * root echo "Ufffi" $(date) >> /tmp/cron_d_test 
*/1 * * * * dietpi ERRRORRRRR
==========
/etc/cron.d/test4.sh
-rwxr--r-- 1 root root 77 Jul 22 18:06 /etc/cron.d/test4.sh
----------
*/1 * * * * echo "Ufffi" $(date) >> /tmp/cron_d_test4 
*/1 * * * * ERRRORRRRR
==========
/etc/cron.d/test2.sh
-rwxr--r-- 1 root root 89 Jul 22 18:06 /etc/cron.d/test2.sh
----------
*/1 * * * * root echo "Ufffi" $(date) >> /tmp/cron_d_test2 
*/1 * * * * dietpi ERRRORRRRR
==========
/etc/cron.d/test3.sh
-rw-r--r-- 1 root root 77 Jul 22 18:06 /etc/cron.d/test3.sh
----------
*/1 * * * * echo "Ufffi" $(date) >> /tmp/cron_d_test3 
*/1 * * * * ERRRORRRRR

Also

root@DietPi:/# cat /etc/cron.hourly/test
#!/bin/bash
echo "UFFFF" $(date) >> /tmp/hourly_test
exit 1337

Expected behaviour

See a bunch of log files in /tmp. Also see error messages in journalctl -u cron as well as error mails being sent out.

Actual behaviour

Only the cron.hourly job seems to be running (/tmp/hourly_test is logged to every hour).
However, none of the cron.d jobs are running.

Extra details

I know that cron jobs for every minute are deactivated (/etc/crontab/etc/cron.minutely). That is ok.
Still I would expect the test jobs in cron.d executed at least hourly.

I do see other jobs in /etc/cron.d being executed, though, which are not running every minute, but more on a daily basis.

I’m still kind of debugging the situation. Let me know if you need more info.

Cheers

Hello, my first guess is that you have to use absolute paths in the cron jobs, mabye it’s not working bc of that. E.g: /usr/bin/echo instead of echo.

So maybe you can change one of the scripts to

*/1 * * * * /usr/bin/echo "Ufffi" $(date) >> /tmp/cron_d_test 
*/1 * * * * /usr/bin/echo "ERRRORRRRR"

and test again.

There is a service cron.service which will check the files every minute and executes the jobs, if necessary.

I added the abs paths for the commands (/usr/bin/echo).

Still same: The minutely crons are not executed.

journalctl -u cron.service doesn’t list them either as being executed ever (other files in /etc/cron.d which e.g. run hourly ARE shown in the journal).

Well, I did find the reason.

Apparently the file extension *.sh was the issue. If I just name the file /etc/cron.d/test then it is interpreted by cron.service : )

2 Likes

See also here: run-parts(8) [linux man page]

Yes correct. The extension was causing the issue. You already found correct man pages.