I have a script which gives output in a file and doing few awk operations on that output file and mixing the output of two files using paste -d and then sending the email of newly created file to email. If i run same script from command line, its giving output and sending email as well, but if i use same command for cron job. Its not sending email and /var/log/cron gives this message. "CROND[6235]: (root) MAIL (mailed 125 bytes of output but got status 0x0043#012)". No info for message code (0x0043#012). Please suggest.
- 5,932
- 4
- 20
- 26
- 1
1 Answers
From question's comments section, I see that SELinux is preventing your cron job from sending e-mails. The denial does not happen on a manual run from command line because SELinux does not confine interactive sessions by default. Jobs launched by Cron, on the other side, are confined.
I am not sure about the reason why a SELinux denial has been generated in your CentOS 7 system. I tried to run mail command from Cron in a fully-updated CentOS 7 system and the message has been sent successfully. I suggest you to ensure that your server has the latest packages installed (yum upgrade) and perform a SELinux relabeling in entire filesystem (touch /.autorelabel && reboot).
Follow standard SELinux troubleshoot steps in case your cron job continues to fail after the relabeling. Or, instead, you may configure permissive mode permanently:
- Option 1: Configure SELinux permissive mode on
cronservice:
# semanage permissive -a crond_t
- Option 2: Configure SELinux permissive mode on entire system:
# sed -ri.bak 's/^(SELINUX=).*/\1permissive/' /etc/selinux/config && reboot
- 2,497
- 10
- 20
-
Other cron job are working fine and sending email. Ex:- /1 * * * ./k1.sh | tee test-k1.txt | mail -s "Test-k1" user@XXXXX.com – Rahul Mar 05 '20 at 11:53
setenforce 0)? Could you also provide the code snippet that sends the e-mail? – Anderson Medeiros Gomes Mar 05 '20 at 08:11crontab -e. I initially imagined that you were creating entries in/etc/crontabfile. Please, could you edit your question and add both crontab entries there (the one who is working and the one who is failing to send e-mails)? Could you also retrieve any related SELinux denial messages by runningausearch -ts recent -sv no? – Anderson Medeiros Gomes Mar 05 '20 at 19:17