Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to (RhetTbull) Re: Seeking tutelage by RhetTbull
in thread Seeking tutelage by Gnuser

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-24 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found