Big time thanks to
rincew,
grinder,
jeffa,
jwest,
mt2k,
hofmator,
kvale,
atoplc,
fruiture, (if I forgot you and
you helped me, I don't mean it as an insult. Just lost track).
As a novice, while
attempting to write this code, I was urged by many colleagues
to use a different language (Java or Korn Shell). But I stuck
with Perl and thanks to you all, now have a working program
that does exactly what I hoped for!
If it wasn't for this site, I would not continue to work so
hard at continuing my Perl education. I thank you for that.
I manage several (6) AV Servers (Norton AV Corporate Edition).
These servers push AV Defs and schedule scans on the 897
managed clients.
We only use a 'trusted' source for AV Sig updates. While this
trusted source provides a weekly 'liveupdate', Symantec
releases new 'all inclusive' updates almost daily and the trusted
source posts those almost immediately but holds on to the 'liveupdates'
for about a week or so.
Many of the subscribers of the systems complained that 'MY'
updates (the liveupdates) were always behind. So...I set about automating the
all inclusive updates.
From a *NIX machine (Solaris or Linux) I update from the trusted
site, twice daily. I then have an AT script on the AV Servers
that ftp's, executes and distributes the avdefs.exe file once per day.
At least, that is my concept. This of course has to go into
my production lab for a week, then I can roll it out for real
Here is my code. Thank you all very much for helping me to
accomplish what probably sounds like a very trivial task, but
for me is a major milestone.
#!/usr/bin/perl -w
use strict;
use Net::FTP;
use Mail::Mailer;
my $host = 'www.trustedftpsite.org';
my $user = 'anonymous';
my $pass = 'updatepuller@avtrustingclient.org';
my $remote_dir = '/pub/antivirus/NAV/signatures';
my $destination_dir = 'current-sig';
my $type = 'sendmail';
my $mailprog = Mail::Mailer->new($type);
my @lupd = ();
if(-e "./lastupdate.txt") {
open(LASTUPDATE,"./lastupdate.txt")
or die "Error while opening lastupdate.txt ($!)";
chomp( @lupd = <LASTUPDATE> );
close(LASTUPDATE)
or die "Error while closing lastupdate.txt ($!)";
}
my %haveit;
@haveit{ @lupd } = (1) x @lupd;
my $ftp = Net::FTP->new($host, Debug => 1);
$ftp->login($user,$pass)
or die "Could not connect to ftp server ($!)";
my @listing = grep /x86\.exe$/i, $ftp->ls($remote_dir);
my @newupdate;
$ftp->type("I");
for my $file (@listing) {
next if $haveit{$file};
if ($ftp->get($file, "$destination_dir/avdefs.exe")) {
mailer($file);
push @newupdate, $file;
}
}
$ftp->quit;
open(NEWUPDATE,">>./lastupdate.txt")
or die "Couldn't open lastupdate.txt for appending ($!)";
print NEWUPDATE map "$_\n", @newupdate;
close(NEWUPDATE)
or die "Closing lastupdate.txt failed ($!)";
sub mailer {
my $file = shift;
my %headers = (
'To' => 'iwannaknow@trustingclient.org',
'From' => 'Antivirusupdater@yournewdefs.com',
'Subject' => 'New AntiVirus Signatures brought down'
);
$mailprog->open(\%headers);
print $mailprog "The Latest AntiVirus signature is $file.\n";
$mailprog->close;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.