home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.admin
- Path: sparky!uunet!stanford.edu!ames!nsisrv!kong!arensb
- From: arensb@kong.gsfc.nasa.gov (Andrew Arensburger - RMS)
- Subject: Re: Mail from cron to root
- Message-ID: <1992Nov5.152541.15047@kong.gsfc.nasa.gov>
- Organization: Goddard Space Flight Center
- References: <BwwoBJ.F9t@eis.calstate.edu>
- Date: Thu, 5 Nov 92 15:25:41 GMT
- Lines: 52
-
- pete@eis.calstate.edu (Pete Kaplan) writes:
- >Is there any way to suppress the mail that cron sends to root if a cron
- >has any output?
-
- We use a local script called 'eem' (for Eat Empty Mail), included
- below. It reads stdin and pipes it to mail iff it contains any non-
- whitespace characters.
- We use it as
-
- 10 5 * * * rm-core-files 2>&1 | eem -s "Core file removal" sysadm
-
- and voila! No mail unless something exceptional happens.
-
- ----- begin included file ----------------------------------------
- #!/usr/very.local/bin/perl
- #
- # EEM - Eat Empty Mail
- # Send mail iff stdin is nonempty. Takes the same parameters as 'Mail'.
- #
-
- # Get the arguments
- @mailargs = @ARGV;
- @ARGV = ();
-
- # Add quotes if necessary
- foreach $i (0..$#mailargs)
- {
- $mailargs[$i] = "'".$mailargs[$i]."'" if ($mailargs[$i] =~ /\s/);
- }
-
- $msg = '';
- while (<>)
- {
- $msg .= $_; # Save this, in case the message is nonempty
- &sendmail if (!/^\s*$/); # Send mail if necessary
- }
-
- # SENDMAIL
- # Copy stdin to 'Mail'.
- sub sendmail
- {
- open(MAIL,"| /usr/ucb/Mail @mailargs") && select(MAIL);
- print $msg;
- print while (<>);
- exit 0;
- }
- ----- end included file ------------------------------------------
- --
- Andrew Arensburger | Why can't I just say
- arensb@kong.gsfc.nasa.gov | perl -e '$]++'
- ...!uunet!dftsrv!kong!arensb | to upgrade to the next patch level?
-