home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / admin / 6052 < prev    next >
Encoding:
Text File  |  1992-11-05  |  1.7 KB  |  62 lines

  1. Newsgroups: comp.unix.admin
  2. Path: sparky!uunet!stanford.edu!ames!nsisrv!kong!arensb
  3. From: arensb@kong.gsfc.nasa.gov (Andrew Arensburger - RMS)
  4. Subject: Re: Mail from cron to root
  5. Message-ID: <1992Nov5.152541.15047@kong.gsfc.nasa.gov>
  6. Organization: Goddard Space Flight Center
  7. References: <BwwoBJ.F9t@eis.calstate.edu>
  8. Date: Thu, 5 Nov 92 15:25:41 GMT
  9. Lines: 52
  10.  
  11. pete@eis.calstate.edu (Pete Kaplan) writes:
  12. >Is there any way to suppress the mail that cron sends to root if a cron
  13. >has any output?  
  14.  
  15.     We use a local script called 'eem' (for Eat Empty Mail), included
  16. below. It reads stdin and pipes it to mail iff it contains any non-
  17. whitespace characters.
  18.     We use it as
  19.  
  20. 10 5 * * * rm-core-files 2>&1 | eem -s "Core file removal" sysadm
  21.  
  22. and voila! No mail unless something exceptional happens.
  23.  
  24. ----- begin included file ----------------------------------------
  25. #!/usr/very.local/bin/perl
  26. #
  27. # EEM - Eat Empty Mail
  28. # Send mail iff stdin is nonempty. Takes the same parameters as 'Mail'.
  29. #
  30.  
  31. # Get the arguments
  32. @mailargs = @ARGV;
  33. @ARGV = ();
  34.  
  35. # Add quotes if necessary
  36. foreach $i (0..$#mailargs)
  37. {
  38.     $mailargs[$i] = "'".$mailargs[$i]."'" if ($mailargs[$i] =~ /\s/);
  39. }
  40.  
  41. $msg = '';
  42. while (<>)
  43. {
  44.     $msg .= $_;    # Save this, in case the message is nonempty
  45.     &sendmail if (!/^\s*$/);    # Send mail if necessary
  46. }
  47.  
  48. # SENDMAIL
  49. # Copy stdin to 'Mail'.
  50. sub sendmail
  51. {
  52.     open(MAIL,"| /usr/ucb/Mail @mailargs") && select(MAIL);
  53.     print $msg;
  54.     print while (<>);
  55.     exit 0;
  56. }
  57. ----- end included file ------------------------------------------
  58. --
  59. Andrew Arensburger            | Why can't I just say
  60. arensb@kong.gsfc.nasa.gov     |     perl -e '$]++'
  61. ...!uunet!dftsrv!kong!arensb  | to upgrade to the next patch level?
  62.