Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to email webalizer output

Status
Not open for further replies.

md1750

MIS
Apr 18, 2001
80
US
I am looking for a script that will email a weekly ouput of webalizer to me
 
You will need to write a perl script that compresses the directory and then emails it out via your SMTP server.

Pick a scripting language your system can run and head on over to that forum, I think thats your best bet.
 
If your defintion of 'Help' is 'write my script for me' then no, your better off at for that.

If by 'help' you mean that you will do some research, select a language for your platform and begin to attempt this task on your own, coming to us for advice and specific issues, then yes, I'll help.
 
I will like to use perl and module Net::SMTP.How do I begin to code the directory compression.
 
This is what I have so far.Please look through for any syntax erros.I will appreciate your comments:
#!/usr/bin/perl -w


#use strict;
use Net::SMTP;
use Net::Config;

print "Content-type: text/plain", "\n\n";

system("cd /array1/var/
system("/usr/bin/webalizer");

# This debug flag will print debugging code to your browser,
# depending on its value
# Set this to 1 to send debug code to your browser.
# Set it to 0 to turn it off.

my $DEBUG = 1;

if($DEBUG)
{
$| = 1;
open(STDERR, ">&STDOUT");
}

# Set this variable to your smtp server name
my $ServerName = "mailfwd.nih.gov";

# Create a new SMTP object
$smtp = Net::SMTP->new($ServerName, Debug => 1);

# If you can't connect, don't proceed with the rest of the script
die "Couldn't connect to server" unless $smtp;

# Initiate the mail transaction
# Your "real" email address
my $MailFrom = "root\@rhlab.nih.gov";

# Recipient's "real" email address
my $MailTo = "benmartins\@blackplanet.com";

$smtp->mail( $MailFrom );
$smtp->to( $MailTo );

# Start the mail
$smtp->data();

# Send the header
# This address will appear in the message
$smtp->datasend("To: enmartins\@blackplanet.com\n");

# So will this one
$smtp->datasend("From: root\@rlab.nih.gov\n");
$smtp->datasend("Subject: Test Message\n");
$smtp->datasend("\n");

# Send the body.
$smtp->datasend("Hello World!\n\n");

# Send the termination string
$smtp->dataend();

# Close the connection
$smtp->quit();

exit;
 
A quick look and it seems fine to me, does it work?

I also do not see your attachment going out, I recommend Mime::Lite for that. You can set it to use Net::SMTP but it will handle the connection internally rendering a lot of this code unneccesary.
 
It ran but did not send any webalizer output.It also gave an error that states: "my" variable $MailTo mask earlier declaration in some scope at /opt/admin/scripts/webstats.pl line 42.What am I doing.Help.
 
Of cousre it did not, your not sending that output anywhere. You just sending 'Hello World'.

 
I have changed datasend to the proper link and it is working fine.Thanks for your assistance all these days.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top