in reply to Seeking tutelage
You're on the right track using Net::FTP for FTP access. Here's some sample code that gets a remote file: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; }
Read the Net::FTP documentation for more detail.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();
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (RhetTbull) Re: Seeking tutelage
by Stegalex (Chaplain) on Mar 09, 2002 at 15:44 UTC |