Hi,

----- Original Message ----
From: Rob Dixon <[EMAIL PROTECTED]>
To: Michael Alipio <[EMAIL PROTECTED]>
Cc: beginners@perl.org
Sent: Monday, January 22, 2007 10:46:40 AM
Subject: Re: compressing files into tar.gz (which module do you prefer)

Michael Alipio wrote:
> Hi,
> 
> After parsing a log and writing it into a file, I now, have to compress it
> into tar.gz. Right now, I'm doing a search at CPAN and there where too many
> modules out there with "compress" or "archive" search keyword.
> 
> What do you suggest?

> > Archive::Tar


Right now, I'm playing with Compress::Zlib.

I have a logfile wich contains logs from different devices.
Now I have a sub which extracts and separates each device's logs.

sub extractlog {

my $clientname=shift;
my $log=shift;
my $year=shift;
my $date=shift;

## create the necessary path in "/client_name/year" notation
mkpath ($clientname.'/'.$year,1);

my $datedlog = $clientname.'/'.$year.'/'.$date.'.log';
## the actual log file destination (e.g; client1/2007/2007-01-12.log)

open FH, '>>', $datedlog or die $!;
print FH $log;
close FH;


}

After the all the extraction have been finished, when I looked into a 
particular client's log:

#ls -alsh
22624 -rw-r--r--  1 root  wheel    22M Jan 22 11:03 2007-01-17.log

# wc 2007-01-17.log
   44018  268264 23148149 2007-01-17.log

It's around 22 Mb and  44018 lines.


Now, if I change my sub to this:


sub extractlog {

my $clientname=shift;
my $log=shift;
my $year=shift;
my $date=shift;

## create the necessary path in "/client_name/year" notation
mkpath ($clientname.'/'.$year,1);

my $datedlog = $clientname.'/'.$year.'/'.$date.'.log'.'.gz';
## the actual log file destination (e.g; client1/2007/2007-01-12.log.gz)

my $gzlogfile = gzopen($datedlog, "ab9");

## append that log entry into the $datedlog.
gzlogfile->gzwrite($log);
$gzlogfile->gzclose();

}


And surprisingly, when I looked into the same client:

#ls -alsh
14352 -rw-r--r--  1 root  wheel    14M Jan 22 11:13 2007-01-17.log.gz

It has grown to 14Mb. The compression is almost only 50% of the original 22Mb 
size.
what's more surprising is that, when I tried to gunzip it to uncompress it:

#ls -lahs
7904 -rw-r--r--  1 root  wheel   7.7M Jan 22 11:13 2007-01-17.log

It's only 7.7Mb.. What has happened here?

#wc 2007-01-17.log
15936   96734 8066422 2007-01-17.log

Seems like I have lost 28,082 log entries for that particular client :-(

Any idea what went wrong?



I was following this example:

open(LOG,"<$log_file1")or print "cld not open $log_file1 for reading \n";
      $HTML_LOG = gzopen("$log_file2", "wb")  or print "cld not open
$log_file2 for writing \n";
      while (<LOG>)
      {
         $HTML_LOG->gzwrite($_)
      }
      close(LOG);
      $HTML_LOG->gzclose();
But it differs from my case as I am not continuously reading the logfile and 
'gzwriting' it.
In my case, I'm only reading the logfile, then for every line, decide which 
client it belongs, then call throw it to sub extractlog which in turn writes it 
into gzipped file..








> > Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/









 
____________________________________________________________________________________
TV dinner still cooling? 
Check out "Tonight's Picks" on Yahoo! TV.
http://tv.yahoo.com/

Reply via email to