|Think about Loose Coupling|
Sanity check: Tiny wrapper script for /bin/mailby FloydATC (Deacon)
|on Nov 29, 2013 at 09:02 UTC||Need Help??|
FloydATC has asked for the
wisdom of the Perl Monks concerning the following question:
Problem: Many many crontab entries that used to send mail to root in case of problems automatically by crond must now be tagged with subject lines for classification. Output is generated only if the scripts detect problems so in most cases the pipeline will be empty, causing '/bin/mail' to complain. Obviously I don't want those empty messages. Some versions of '/bin/mail' support a setting 'nonullbody', mine unfortunately doesn't seem to.
Solution: Write a small wrapper to '/bin/mail' called '/usr/bin/mail-if', which only calls '/bin/mail' if the pipeline is non-empty:
Example use:05 12 * * * root /home/atlas/tools/CRON_macscanner | mail-if -s "[Nettverk][Error] CRON_macscanner" firstname.lastname@example.org
Notice that if the cron job itself generates errors on STDERR those messages will still be sent to root, this is by design.
Question: This appears to work as intended. Does anyone see obvious problems with this approach, or perhaps a simpler solution?
Time flies when you don't know what you're doing