#!/usr/bin/perl -w # Description: Custom script to strip stats from a messy file. # HP VERSION use strict; my $int; my $vmstat; my $total; my $sfile = pop or carp("Usage: strip.pl [file]"); my $ofile = "$sfile.out"; open ODATA,">$ofile" or carp("Can't open $ofile for writing"); open DATA,"<$sfile" or carp("Can't open $sfile"); while ( ) { # 1. The script needs to scan thru the file until it finds the date line containing # either GMT or SAST entries. The hour and minute needs to be stored to a varible. # i.e. int=17:00 $int = $1 if ( /(\d{2}:\d{2}:\d{2})\s+(GMT|SAST)/ ); #$int = $1 if ( /(\d{2}:\d{2})\s+(GMT|SAST)/ ); # 2.Scan futher down the file until the text "vmstat 2 60" is found. # This line show data will follow. if ( /^\s*vmstat 2 60/ ) { # There will be 60 lines of actual stats, which needs to be added together # and divided by 60 to provide an average. $total = 0; for my $i (1..3) { # 3 x 20 # 3. Ignore two heading lines, that each contain text "procs" and "avm" respectively =~ /procs/ or die "Input error $_\n"; =~ /avm/ or die "Input error $_\n"; # 4. Hereafter 20 lines of data follow. # I need to to extract columb 16 and 17 - and add them together. for my $i (1..20) { ( =~ / (\d+\s+){15}(\d+)\s+(\d+) /); my ($us, $sy) = ($2, $3); my $sum = $us + $sy; $total += $sum; #print "$i:\t$us, $sy, $sum, $total, ", $total/60, "\n"; } # 5. I would now like to write this as a record to a file. #my ($h, $m, $s) = split /:/, $int; #$s += $total / 60; #print "***$int ", join (':', $h,$m,$s); } #print "$i:\t$us, $sy, $sum, $total, ", $total/60, "\n"; my ($h, $m, $s) = split /:/, $int; $s += $total / 60; #print ODATA "\n***$int -> ", join (':', $h,$m,$s); print ODATA "$h:$m,$s\n"; } } close DATA; close ODATA;