Mini Shell

Direktori : /proc/self/root/opt/sharedrads/oldrads/mysql/
Upload File :
Current File : //proc/self/root/opt/sharedrads/oldrads/mysql/parse-slowqlog

#!/usr/bin/perl

use Getopt::Long;

#Default Options
$programName="pslowq";
my $sortOption;
my $helpOpt;
my @parsedslowq;

sub pusage {
	print "Usage:\n";
	print "\"tail -5000 /var/log/slowqueries | $programName\" or \"$programName < inputfile\" (the latter could be problematic if the log file is large) \n\n";
#This needs finishing.
#	print "Additional Options:\n\n";
#	print "$programName --sort [db|date|qtime|locktime|rowsent|rowsex]";
#	print "\n";
#	print "          db                date              qtime               locktime         rowsent           rowsex \n";
#	print "userna5_root[userna5_root] 081116  1:41:38 Query_time: 5         Lock_time: 0    Rows_sent: 1    Rows_examined: 11923574\n";


};
#Where do you want to go today?
GetOptions(	"sort=s"	=>\$sortOption,
		"help"		=>\$helpOpt,
);

if($helpOpt){
	pusage();
	exit;
}
#Get ready or bleed out.
#if (!$sortOption){ pusage(); exit;  }
#else { print "$sortOption";}
while (<>) { #ugly, clean up this a2p mess later.
    my ($Fld1,$Fld2,$Fld3,$Fld4,$Fld5,$Fld6,$Fld7,$Fld8,$Fld9) = split(' ', $_, 9999);
    if (/# Time:/) {
	$date = $Fld3;
	$Time = $Fld4;
    }
    if (/User@Host/) {
	$db = $Fld3;
    }
    if (/Query_time/) {
	#mycanp5_canprev[mycanp5_canprev]         081121          18:36:03        Query_time:     8 Lock_time:    0 Rows_sent:    26898 Rows_examined:
	$db =~ s/\[.*\]//;
	printf "%25s %10s %10s %10s %5s %10s %6s %10s %8s %15s %8s\n",$db, $date, $Time, $Fld2, $Fld3, $Fld4, $Fld5, $Fld6, $Fld7, $Fld8, $Fld9;
	#$result=sprintf "%s %s $s %s %s\t %s %s\t %s %s\t %s %s\n",$db, $date, $Time, $Fld2, $Fld3, $Fld4, $Fld5, $Fld6, $Fld7, $Fld8, $Fld9;
    }
#    push(@parsedslowq, chomp($result));
}

foreach (@parsedslowq) { print; }
#For future work, it would be nice to get sorting done in the script itself.
#print $#parsedslowq;
#my @sorted_parsedslowq =
#	map { $_->[0] }
#	sort { $a->[1] cmp $b->[1] }
##	map { [ $_, /(\S+)$/ ] }
#	@parsedslowq;
#foreach (@sorted_parsedslowq) { print; }

Zerion Mini Shell 1.0