Ronald Fischer <ronaldf@eml.cc>:
> [snip]
> So before I try one of these, I would like to ask what approach other
> users use to easily send mail using attachments from a script. A
Two, both in perl:
----------------------
#!/usr/bin/perl -w
#
# report.pl
#
# from Spamcop reporter.pl by
jim@$SOMEWHERE.net - 13Jan2002
#
use strict;
open(SENDMAIL, "| /usr/sbin/sendmail -oi -t")
|| die qq(Cannot open sendmail output: $!\n);
print SENDMAIL <<EoF;
From: keeling\@spots.ab.ca
To: submit.$MYID\@spam.spamcop.net
Subject: SPAM/UCE report
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="WowAreSpammersEverStupid"
This is a multi-part message in MIME format.
--WowAreSpammersEverStupid
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
--WowAreSpammersEverStupid
Content-Type: message/rfc822
Content-Disposition: attachment
EoF
while (<STDIN>) {
print SENDMAIL;
}
print SENDMAIL <<EoF;
--WowAreSpammersEverStupid--
EoF
close (SENDMAIL);
----------------------
----------------------
#!/usr/bin/perl
#
# calls ~mx_urban/sh/err_log.sh to grep /var/log/httpd/error_log
# for yesterday's log file events, then mails them out in a gzipped,
# Mime encoded attachment.
#
use strict;
use warnings;
use diagnostics;
use MIME::Lite;
sub usage() {
print qq($0: usage: \"$0 [user\@somewhere.com] [somewhere\@else.com]\"\n);
}
my ($from, $recip);
# who to send it from.
#
if( defined( $ARGV[ 1 ] ) ) {
if( $ARGV[ 1 ] =~ qq(\@) ) {
$from = qq($ARGV[ 1 ]);
} else {
usage();
exit 0;
}
} else {
$from = qq($ENV{USER});
}
# who to send it to.
#
if( defined( $ARGV[ 2 ] ) ) {
if( $ARGV[ 2 ] =~ qq(\@) ) {
$recip = qq($ARGV[ 2 ]);
} else {
usage();
exit 0;
}
} else {
$recip = qq(stephen.keeling\@blah.com);
}
# string to search for in error_log
#
my $day = qx(/bin/date '+%a %b %d' --date=yesterday);
chomp( $day );
# date prefix for output filename.
#
my $fday = qx(/bin/date '+%Y%m%d' --date=yesterday);
chomp( $fday );
# output filename (eg. 20050614_error_log.gz)
#
my $fname = $fday . qq(_error_log.gz);
# see EOF for err_log.sh
#
my $msg = new MIME::Lite;
$msg->build(Type => 'gzip',
Path => "/home/mx_urban/sh/err_log.sh |",
ReadNow => 1,
Filename => "$fname");
$msg->add(From => $from);
$msg->add(To => $recip);
$msg->add(Subject => "Apache error log file snippet - $fname");
$msg->send();
__END__
--------------------------------------------------------------------
#!/bin/bash
#
# err_log.sh
#
# report yesterday's apache error_log entries. this is called
# by a pipe in mmail.pl
#
DAY="$(/bin/date '+%a %b %d' --date=yesterday)"
ALOG=/var/log/httpd/error_log
if [ -f "${ALOG}" ]; then
/bin/grep "${DAY}" ${ALOG} | gzip -9
fi
--------------------------------------------------------------------
----------------------
--
Any technology distinguishable from magic is insufficiently advanced.
(*)
http://www.spots.ab.ca/~keeling Linux Counter #80292
- -
http://www.faqs.org/rfcs/rfc1855.html Please, don't Cc: me.
Spammers!
http://www.spots.ab.ca/~keeling/emails.html