Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Cron Job & Perl

Reply
Thread Tools

Cron Job & Perl

 
 
goooo
Guest
Posts: n/a
 
      03-21-2005
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";}


 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      03-21-2005
goooo <(E-Mail Removed)> wrote:

> It works perfect when I launch it manually from cmd prompt. But via CRON.



Must be something different in the environment then, cwd, env vars, etc...


> All it seems to do is delete the UPDATE.INI & DAT files and bombs out.



What does "bombs out" mean when you say it?

Get any messages or anything like that?


> ################################################## ###############
> #!/usr/bin/perl


use warnings;
use strict;


> opendir (DIR, $dir) or die $!;



What directory are you in here?


> foreach (@dir) {
> if(/dat\-/){



hyphens are not special in regexes, there is no need to backslash them.


> $olddat = substr($_,4,4);}
> }



$olddat = $ 1 if /dat-(....)/;


> print "Old DAT file Version is ","$olddat","\n\n";



Hnuh? What's with all the quotes and commas?

print "Old DAT file Version is $olddat\n\n";


> open(FILE, "$dir/update.ini");



You should always, yes *always*, check the return value from open():

open(FILE, "$dir/update.ini") or
die "could not open '$dir/update.ini' $!";


> if (/FileName\=/ && /dat\-/ && /\.zip/i){

^ ^
^ ^ more needless backslashing

if (/FileName=/ && /dat-/ && /\.zip/i){


> if($olddat!=$newdat){



Whitespace is not a scarce resource, feel free to use as much as
you like to make your code easier to read and understand:

if ( $olddat != $newdat ){

> system("rm","-rf","$dir/dat-$olddat\.zip");

^
^ needless backslashing yet again


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      03-22-2005
goooo wrote:

> 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.
>
> system("wget","ftp://ftp.nai.com/pub/antivirus/datfiles/4.x/update.ini","-P"
> ,"/home/dats");


If your "wget" is someplace other than /bin or /usr/bin (such as
/usr/local/bin), then it's no wonder that it cannot be found
under cron.

Use absolute pathname, or set $ENV{PATH} to a known value.
-Joe
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Equiv of a CRON job? Andrew Banks ASP .Net 8 07-30-2012 07:03 AM
Runs Fine In Perl :: Not As Cron Job Bucker Perl Misc 6 01-17-2007 03:19 PM
cron job times out Nikola Skoric Python 0 11-24-2006 06:50 PM
Ftp via Perl cron job Bill H Perl Misc 4 09-28-2006 06:51 PM
Cron Job through Perl Bob Anastasia Perl Misc 1 06-26-2006 07:03 PM



Advertisments