|There's more than one way to do things|
Sanity check: Tiny wrapper script for /bin/mailby FloydATC (Chaplain)
|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" email@example.com
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