roadtest has asked for the wisdom of the Perl Monks concerning the following question:
The leading character "<" means job started, ">" means job finished. The second field is username. Third field is jobID, which might be reused after this one is done. Since all these are daily jobs, I only care field 8 to calculate run time. Here is what I am trying to do:== < root 26144 c Tue Nov 2 03:10:02 2010 < oracle 26161 c Tue Nov 2 03:10:25 2010 < oracle 26193 c Tue Nov 2 03:10:30 2010 < sybase 26163 c Tue Nov 2 03:10:32 2010 > oracle 26161 c Tue Nov 2 03:10:33 2010 < sybase 26188 c Tue Nov 2 03:10:38 2010 > sybase 26163 c Tue Nov 2 03:10:58 2010 ==
==end code here==#!/usr/bin/perl use strict; use warnings; use Date::Manip; my @owner= qw/oracle sybase/; open (FILE,"cron.log"); while(<FILE>) { chomp; next if (split /[ ]+/)[1] !~ /oracle|sybase/ ; my ($mode,$owner,$job_id,undef,undef,undef,undef,$timestamp,undef) +=split /[ ]+/; #get same jobID finish timestamp and calculate difference, #then save back ${$owner}{$job_id}=DateCalc(${$owner}{$job_id},$timestamp) if ($mo +de=~ /^>/); } close(FILE); foreach $owner(@owner){ foreach (keys %{$owner}) { print "$owner - JobID:$_ - RunTime:${$o +wner}{$_}\n"; };}
Seek a better approach to achieve the target. Thanks in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash array
by jethro (Monsignor) on Nov 03, 2010 at 17:38 UTC | |
|
Re: hash array
by kcott (Archbishop) on Nov 03, 2010 at 17:54 UTC | |
by roadtest (Sexton) on Nov 05, 2010 at 18:44 UTC | |
|
Re: hash array
by liverpole (Monsignor) on Nov 03, 2010 at 18:01 UTC | |
by roadtest (Sexton) on Nov 05, 2010 at 18:28 UTC | |
|
Re: hash array
by toolic (Bishop) on Nov 03, 2010 at 18:02 UTC | |
by roadtest (Sexton) on Nov 05, 2010 at 18:41 UTC | |
|
Re: hash array
by aquarium (Curate) on Nov 03, 2010 at 22:12 UTC | |
|
Re: hash array
by roadtest (Sexton) on Nov 05, 2010 at 02:20 UTC |