My cron service only sends email when in test mode. I can confirm this by running the service interactively:
root:~# crond -n -x bit,test -m 'sendmail'
debug flags enabled: test bit
[25625] cron started
log_it: (CRON 25625) STARTUP (1.7.2)
log_it: (CRON 25625) INFO (RANDOM_DELAY will be scaled with factor 47% if used.)
log_it: (CRON 25625) INFO (running with inotify support)
log_it: ((null) 25625) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0 file_context=system_u:object_r:system_cron_spool_t:s0 (/etc/crontab)
log_it: ((null) 25625) SELinux in permissive mode, continuing (/etc/crontab)
log_it: ((null) 25625) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0 file_context=system_u:object_r:system_cron_spool_t:s0 (/etc/cron.d/0hourly)
log_it: ((null) 25625) SELinux in permissive mode, continuing (/etc/cron.d/0hourly)
log_it: (CRON 25625) INFO (@reboot jobs will be run at computer's startup.)
log_it: (root 25628) CMD (echo "This is a CRON test" > /tmp/crontest.txt)
sendmail: No recipients supplied - mail will not be sent
log_it: (root 25626) CMDEND (echo "This is a CRON test" > /tmp/crontest.txt)
^Clog_it: (CRON 25625) INFO (Shutting down)
Notice that with this set of flags, crond complains that sendmail is missing a recipient. And if I modify the flag to -m ‘sendmail -t’, I will receive an email.
But if I run it without the test flag, the error message does not appear, indicating that the sendmail command was not executed at all.
root:~# crond -n -x bit -m 'sendmail'
debug flags enabled: bit
[25630] cron started
log_it: (CRON 25630) STARTUP (1.7.2)
log_it: (CRON 25630) INFO (RANDOM_DELAY will be scaled with factor 66% if used.)
log_it: (CRON 25630) INFO (running with inotify support)
log_it: ((null) 25630) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0 file_context=system_u:object_r:system_cron_spool_t:s0 (/etc/crontab)
log_it: ((null) 25630) SELinux in permissive mode, continuing (/etc/crontab)
log_it: ((null) 25630) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0 file_context=system_u:object_r:system_cron_spool_t:s0 (/etc/cron.d/0hourly)
log_it: ((null) 25630) SELinux in permissive mode, continuing (/etc/cron.d/0hourly)
log_it: (CRON 25630) INFO (@reboot jobs will be run at computer's startup.)
log_it: (root 25635) CMD (echo "This is a CRON test" > /tmp/crontest.txt)
log_it: (root 25632) CMDEND (echo "This is a CRON test" > /tmp/crontest.txt)
^Clog_it: (CRON 25630) INFO (Shutting down)
Does anyone know what is causing the behaviour?
Thanks.
Installation:
6.16.12-200.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Oct 12 16:31:16 UTC 2025 x86_64 GNU/Linux
ssmtp-2.64-39.fc42.x86_64
cronie-anacron-1.7.2-6.fc42.x86_64
cronie-1.7.2-6.fc42.x86_64
The -m flag doesn’t override the crontab: it means “use the following command to send mail when necessary”, rather than “run the following command as the ‘payload’, instead of the commands in the crontab”.
Right. I think the ‘real’ problem is one step back from the one described in the thread title: it’s more like “in non-test mode, the tasks executed by cron don’t generate any output that needs to be emailed” than “in non-test mode, cron tries but fails to send a mail”.
I realized that it may be related to stdout or stderr when I looked at the email itself. The email is not giving me the output of the command but instead its cron telling me that it is not exec’ing the command.
debug DTEST is on, not exec'ing command.
cmd='echo "This is a CRON test" > /tmp/crontest.txt' shell='/bin/sh'