4

Ubuntu 14.04lts with Perl 5.18.2.

This is a special case where Google did not help me. I do not want to turn off email for all cron jobs, I have about 15 jobs in my crontab. I need to see the emails cron sends me if there are errors.

This one job is a special case for which I need a solution. I have a bash script in my crontab which calls a perl script which is setup to check for email every 5 minutes. (It is not possible for me to setup a full MTA.) If there is no email the script does not output anything to STDOUT or STDERR yet cron still sends me a blank email with the full path of the bash script in the subject.

  1. I want cron and the Perl script to send me email if the perl script finds email and processes it, including if there are errors.
  2. I don't want cron to send me a blank email if there is no output from the Perl script because no email was found. The script runs every 5 minutes.

Anyone have any ideas?

EDIT: Confirmed. It was a stray newline that was my problem. Problem solved. Cron does not send an email if there is no output. Thank you! Your comment helped.

2
  • 3
    cron doesn't send mails on no output. Are you sure it is printing nothing to stderr/out? Not even blank lines or whitespace?
    – muru
    Dec 22 '14 at 19:31
  • I'm testing this right now. I found a newline and removed it. So far, no emails. I couldn't see the newline in alpine, my email reader.
    – Bulrush
    Dec 22 '14 at 19:40
2

It was a stray newline causing the blank email every 5 minutes.

Cron only sends an email if the cron job/program run has output. My output was a newline, which of course, I couldn't see in Alpine, but it was there. I found the newline that my program was printing and removed it.

Now I design my cron programs to never output anything unless it gets past the parameter checking.

2
  • Can you elaborate please? As it stands this answer is going to be deleted soon because it's too vague. Dec 23 '14 at 16:30
  • @DavidFoerster actually, it looks like that's all there is. cron doesn't send emails if there's no output, but if there's any output at all, even a blank line, it will send emails. Removing the superfluous newline was all that was necessary, it seems.
    – muru
    Dec 23 '14 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.