#!/usr/bin/perl -w # # Copyright Yves Dorfsman 2006. # # $Revision: 0.2 $ # $Date: 2006/04/20 04:44:46 $ # # This is a very early very crude version. I will finish it, but I have a need # to extract data very soon.... # # ----------------------------------------------------------------------------- # extrallator is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # extrallator is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public # License for more details. # # You should have received a copy of the GNU General Public License # along with Orca in the COPYING-GPL file; if not, write to the Free # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # 02111-1307 USA # ----------------------------------------------------------------------------- # # extrallator is a simple perl script used to extract one column from a list # of files that were produced by an Orca (http://orcaware.com/orca) data # gatherer such as orcallator, procallator or winallator. # # syntax for now is: # extrallator column_name list_of_files [file [directory]] # # eg: extrallator 'mem_used%' /var/orca/procallator/ginette # # Assumptions: # -the columns name are on the first line # -the file extensions are correct (gz = gziped etc...) # -.gz ==> gzip'ed, .bz2 ==> bzip2'd # -gzip and bzip2 are in the path # use strict; sub usage { print "\nWrong syntax....\n"; print "I'll update the usage section later\n\n"; } if ($#ARGV < 1) { usage; exit 1; } my $pattern = shift @ARGV; # Build a list of files. If argument is a directory, open all the files in # that directory, but do not recurse (well, at least for now). #print "column: $column\n"; my @files; foreach (@ARGV) { my $entry = $_; if (-d $entry) { opendir(DIR, $entry); while (defined(my $file = readdir(DIR))) { my $path_to_ent = $entry . "/" . $file; push @files, $path_to_ent if (-f $path_to_ent); } closedir DIR; } else { push @files, $entry; } } # Now open each file and look for the pattern foreach (@files) { my $file = $_; my $decomp; my $timestampIndex; my $patternIndex; $decomp = "gizp" if (/.*\.gz$/); $decomp = "bzip2" if (/.*\.bz2$/); if (defined $decomp) { open FILE, ("$decomp -cd $file |"); } else { open FILE, $file; } # read first line which should be the titles my $line = ; chomp $line; my @lineList = split / +/, $line; for (my $i = 0 ; $i < $#lineList ; $i++) { $timestampIndex = $i if $lineList[$i] =~ /^timestamp$/; $patternIndex = $i if $lineList[$i] =~ /^$pattern$/; } # the pattern won't necessarely be present in all the files # (timestamp should though, but just in case) next if (! defined $timestampIndex); next if (! defined $patternIndex); while ($line = ) { chomp $line; @lineList = split / +/, $line; # transform the timestamp into human time (my $lts, my $ltm, my $lth, my $ltd, my $ltM, my $lty, my $ltw, undef, undef) = localtime($lineList[$timestampIndex]); $lty += 1900; $ltM++; $ltM = sprintf "%02d", $ltM; $lth = sprintf "%02d", $lth; $ltm = sprintf "%02d", $ltm; $lts = sprintf "%02d", $lts; print "$lty-$ltM-$ltd $lth:$ltm:$lts $lineList[$patternIndex]\n"; } close FILE; }