[Omaha.pm] Log files might be bz2'd hack

Jay Hannah jhannah at omnihotels.com
Thu Jun 9 09:23:03 PDT 2005


I thought this was an interesting hack...

I've got these log files that may or may not be .bz2'd. Plus I don't necessarily know their whole filename, I only know their date. So, if I want the files for yesterday I do:

$ ls -a /junk/__peglogs/comserver-trans-a.log.20050608*
/junk/__peglogs/comserver-trans-a.log.20050608235900.bz2

and that file (or files) may or may not be bz2'd. So my code to walk through all the files that are there now looks like this:

my $glob = "/junk/__peglogs/comserver-trans-a.log.$y$m$d";
my $cat = "cat";
if (`ls $glob*.bz2 2>/dev/null`) {
   $cat = "bzcat";
}
open (IN, "$cat $glob* |");
while (<IN>) {
   ...etc...

It only works if all files either are or are not .bz2'd. You can't mix and match.

Neat? Not? -ponder-

Shrug,

j



More information about the Omaha-pm mailing list