Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

(RhetTbull) Re: Seeking tutelage

by RhetTbull (Curate)
on Mar 08, 2002 at 17:51 UTC ( #150381=note: print w/ replies, xml ) Need Help??


in reply to Seeking tutelage

Is it possible? Most certainly -- everything you asked about is possible and in most cases, rather easy. I recommend reading up on the following modules (most of which can probably be installed using the "ppm" command if you're using ActiveState perl as I suspect you are, or using the cpan shell if you're on a unix system ("perl -MCPAN -e shell"). To send email, I prefer the MIME::Lite module which makes it nice and easy (including sending attachments). Here's some sample code that illustrates using MIME::Lite to send a log file as a message body (this is ripped from some code I use) and sends it.

use warnings; use strict; use MIME::Lite; my $body; { #snarf the file into the variable $body local $/ = undef; open SCI_DUMP_OUT, "<$sci_dump_out" or die "could not open file $s +ci_dump_out: $! ; $body = <SCI_DUMP_OUT>; close SCI_DUMP_OUT or warn "could not close file $sci_dump_out: $! +"; } #you must define $to, $cc, $subject, $from, and $smtp_server my %msg = ( to => $to, cc => $cc, subject => $subject, body => $body, from => $from, server => $smtp_server); send_email(%msg); sub send_email { #send email via SMTP using MIME::Lite my %email = @_; my @must_have = qw(server from to subject body); foreach (@must_have) {die "send_email: must provide parameter: '$_ +'" if not defined $email{$_}}; MIME::Lite->send('smtp',$email{server},Timeout=>60); my $msg = MIME::Lite->new( From => $email{from}, To => $email{to}, Cc => $email{cc}, Subject => $email{subject}, Type => 'multipart/mixed' ); $msg->attach(Type => 'TEXT', Data => $email{body}, ); $msg->send; }
You're on the right track using Net::FTP for FTP access. Here's some sample code that gets a remote file:
use strict; use warnings; use Net::FTP; my ($host, $user, $pass) = qw(host.some.domain username password); my $ftp = Net::FTP->new($host) || die "Could not open connection to '$ +host'"; $ftp->login($user,$pass) or die "could not login: $!"; $ftp->cwd("test"); $ftp->get("that.file"); $ftp->quit();
Read the Net::FTP documentation for more detail.

For problem 2, you could also use Net::FTP to push the file to the servers (assuming they have FTP servers installed and running). One approach would be to use a script to push (via FTP) the files to the servers. Have another script that runs on the servers on a scheduled basis and when it sees new files in your incoming directory, it unzips them and processes them. See Archive::Zip for dealing with .ZIP files as well as IO::Zlib for dealing with .gz files.

As for scheduling things on NT, you can use the "at" command or try the task scheduler. Or if you're running Windows 2000, you can use the Scheduled Tasks service via the Control Panel. To schedule a perl script, I usually use the full path the perl program and the script name as the command for task to run to make sure everything finds the right path. For example, to schedule the task "foo.pl" to run, I set the command to run (in the Task Scheduler or Scheduled Tasks setup) to be something like "c:\Perl\bin\perl.exe c:\foo\foo.pl")

You might also like to read Dave Roth's "Win32 Perl Scripting: The Administrator's Handbook" for more details about how to use Perl to do admin tasks on Windows.


Comment on (RhetTbull) Re: Seeking tutelage
Select or Download Code
Re: (RhetTbull) Re: Seeking tutelage
by Stegalex (Chaplain) on Mar 09, 2002 at 15:44 UTC
    Props to RhetTBull. MIME::Lite is the ticket.

    Spend some time learning about MIME types and pay close attention to the mail reader being used by your clients. AOL can't handle things like multipart/alternative mails. Yahoo isn't too good at it either. Some really paranoid mail readers such as SQWebmail won't let you view HTML mails. So if possible, keep your life simple and use plain old text for automated mails that are going out to the world. Eat chicken every day. I like chicken.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://150381]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-12-28 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls