I am having trouble getting cron to email an attachment based on a predefined condition set in the bash script. The following is my /etc/crontab setting:
SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTOemail@example.com MAILFROMfirstname.lastname@example.org 0,30 * * * * root /some/bash/script
The bash script contains:
#!/bin/bash PATH=/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin if [ -s /var/log/test ]; then echo "test" | mailx -s "test" -a /var/log/test -r email@example.com firstname.lastname@example.org fi exit 0
The problem is that cron sometimes send out an email despite the test file being empty. Sometimes the subject header "test" is overridden by cron with its own subject header. Without setting "MAILFROM", cron will use root despite the setting in mailx.
I am very new to cron, so I am not very sure whether I have done things correctly. Would appreciate if somebody can point out what is causing the problem.