I have something similar called "cmail", which sends mail via the mailx
command. Feel free to use/modify as needed.

Kevin

#!/usr/bin/perl 
########################################################################
#
# Script:        cmail
#
# Author:        k. cOLLINS
#
# Date:          03/15/99
#
#
#
#--------------------#         Description
#--------------------#
# This script is designed to receive a pipe from cron jobs (actually,
#
# it should be ok for any pipe). Its purpose is to send mail only if
#
# there is output from the pipe.
#
#
#
#--------------------#        Modifications
#--------------------#
#
#
# mm/dd/yy CAI    Description
#
# ======== ====   ===========
#
#
#
########################################################################
#
#--------------------#           Modules
#--------------------#
use Getopt::Std;
use File::Basename;

#--------------------#       Global Variables
#--------------------#
$BaseName = basename ($0);
#--------------------#        Script Starts
#--------------------#

# check for options
getopts('s:');

# build recipient list
$Recipients = join(',', @ARGV);

# complain and die if no recipients
Usage() if (! $Recipients);

# add subject if specified
if ($opt_s)
{
    $MailCmd = "mailx -s '$opt_s' $Recipients";
}
else
{
    $MailCmd = "mailx $Recipients";
}

# read a line of input
$Line = <STDIN>;

# exit if there is nothing
exit if (! $Line);

# open mail program or die
open (MAIL, "| $MailCmd") || die "Can't open pipe for $MailCmd: $!";

# print the line already read
print MAIL $Line;

# print the rest of the input
while (<STDIN>)
{
    print MAIL;
}

# close the cmd pipe
close MAIL;

#--------------------#         Script Ends
#--------------------#
#--------------------#      Subroutines Start
#--------------------#
sub Usage
{
    print "usage: $BaseName [-s subject] recipient [recipient ...]\a\n";
    exit;
}

#--------------------#       Subroutines End
#--------------------#
 

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Brian Long
Sent: Wednesday, July 16, 2008 5:42 AM
To: Red Hat Enterprise Linux 5 (Tikanga) discussion mailing-list
Subject: Re: [rhelv5-list] emails from cron

On Wed, 2008-07-16 at 11:51 +0100, solarflow99 wrote:
> I wonder what the best way is to receive email notifications from cron
> job scripts?  Say I put a script in cron.daily, and I don't want email
> for all the other cron jobs in there, just to see the output the one I
> added.

I've been using a simple Perl script called "mailif".  You run your cron
job like this:

0 * * * * /path/to/script 2>&1 | /path/to/mailif -s "Cron output"
[EMAIL PROTECTED]

mailif detects empty output or just a single dot and does not send the
email.  It passes all its arguments to /bin/mail.

/Brian/
-- 
       Brian Long                             |       |
                                          . | | | . | | | .
                                              '       '
                                              C I S C O

_______________________________________________
rhelv5-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/rhelv5-list

_______________________________________________
rhelv5-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/rhelv5-list

Reply via email to