G
goooo
I've got a perl script that I'm having problems trying to launch from CRON.
My script deletes UPDATE.INI, checks to see if file DAT version specified in
UPDATE.INI is same in directory. (ie. DAT-4450.ZIP) If not it deletes old
file and downloads the latest file.
It works perfect when I launch it manually from cmd prompt. But via CRON.
All it seems to do is delete the UPDATE.INI & DAT files and bombs out.
Heres my cron line -
24 11 * * * /usr/bin/perl
/etc/periodic/naidat_update.pl >/dev/null 2>&1
Heres my script -
#################################################################
#!/usr/bin/perl
use Net::FTP;
use Cwd;
my $dir = "/home/dats";
my $olddat = "unknown";
my $newdat = "unknown";
opendir (DIR, $dir) or die $!;
my @dir = readdir DIR;
closedir DIR;
foreach (@dir) {
if(/dat\-/){
$olddat = substr($_,4,4);}
}
print "Old DAT file Version is ","$olddat","\n\n";
system("rm","-rf","$dir/update.ini");
print "Downloading latest UPDATE.INI file\n\n";
system("wget","ftp://ftp.nai.com/pub/antivirus/datfiles/4.x/update.ini","-P"
,"/home/dats");
open(FILE, "$dir/update.ini");
while (<FILE>){
chomp;
if (/FileName\=/ && /dat\-/ && /\.zip/i){
$newdat = substr($_,13,4);}
}
close FILE;
print "New DAT file Version is $newdat\n\n";
if($olddat!=$newdat){
print "Deleting old DAT file $olddat\n\n";
system("rm","-rf","$dir/dat-$olddat\.zip");
print "Downloading latest DAT file $newdat\n\n";
system("wget","ftp://ftp.nai.com/pub/antivirus/datfiles/4.x/dat-$newdat\.zip
","-P","/home/dats");
} else{
print "DAT file Up To Date\n\n";}
My script deletes UPDATE.INI, checks to see if file DAT version specified in
UPDATE.INI is same in directory. (ie. DAT-4450.ZIP) If not it deletes old
file and downloads the latest file.
It works perfect when I launch it manually from cmd prompt. But via CRON.
All it seems to do is delete the UPDATE.INI & DAT files and bombs out.
Heres my cron line -
24 11 * * * /usr/bin/perl
/etc/periodic/naidat_update.pl >/dev/null 2>&1
Heres my script -
#################################################################
#!/usr/bin/perl
use Net::FTP;
use Cwd;
my $dir = "/home/dats";
my $olddat = "unknown";
my $newdat = "unknown";
opendir (DIR, $dir) or die $!;
my @dir = readdir DIR;
closedir DIR;
foreach (@dir) {
if(/dat\-/){
$olddat = substr($_,4,4);}
}
print "Old DAT file Version is ","$olddat","\n\n";
system("rm","-rf","$dir/update.ini");
print "Downloading latest UPDATE.INI file\n\n";
system("wget","ftp://ftp.nai.com/pub/antivirus/datfiles/4.x/update.ini","-P"
,"/home/dats");
open(FILE, "$dir/update.ini");
while (<FILE>){
chomp;
if (/FileName\=/ && /dat\-/ && /\.zip/i){
$newdat = substr($_,13,4);}
}
close FILE;
print "New DAT file Version is $newdat\n\n";
if($olddat!=$newdat){
print "Deleting old DAT file $olddat\n\n";
system("rm","-rf","$dir/dat-$olddat\.zip");
print "Downloading latest DAT file $newdat\n\n";
system("wget","ftp://ftp.nai.com/pub/antivirus/datfiles/4.x/dat-$newdat\.zip
","-P","/home/dats");
} else{
print "DAT file Up To Date\n\n";}