use logger(1) to reduce sysadmin mail
Posted by rossen
on Tue 29 Sep 2009 at 09:41
I often find sysadmin mailboxes filled with thousands of un-read messages originating from the output of cronjobs. The messages are usually banal but interesting to keep for a while, thus the sysadmins file them and forget them, sometimes for years. Some sysadmins simply avoid their mailbox if it has 12,000 messages in it. Important warnings get ignored this way.
Here is a tip that will help to reduce the clutter of the sysadmin's mailbox: pipe the STDOUT (and optionally STDERR) of simple cronjobs into your system log using the logger(1) program which is part of the "bsdutils" package.
For example, suppose you have a job called "my-backup" that backs-up a directory and you want to keep the verbose-but-boring output "just in case". Instead of a specifying the cronjob in /etc/cron.d/backup as
@hourly root /usr/local/sbin/my-backup
redirect the standard output to the syslog with
@hourly root /usr/local/sbin/my-backup | logger -t my-backup
or, if the error messages are known to be non-urgent, redirect output AND errors to the syslog with
@hourly root /usr/local/sbin/my-backup 2>&1 | logger -t my-backup
The option "-t my-backup" will nicely tag each line with the string "my-backup", allowing one to easily grep the contents of /var/log.