[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Omaha.pm] Log files might be bz2'd hack
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