www.pudn.com > filecollector.rar > iarstat.p


#!/usr/local/perl5/bin/perl

#################################2001/12/18 edited by yzliu####################################

use strict;
use FileHandle;
use Getopt::Long;
###############################################################################################
#&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
#
#                       main process
#
#&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&


my ($report_file,$output_dir);
my ($rfd,$wfd,$line,$msc_name,$i,$o);
my @Iar_obj=( );
$o=$i=0;

my $Usage = "\n\tUsage: $0 report_file \n\n";
$report_file = $ARGV[0];
$output_dir  = $ARGV[1];
if(!( $report_file && $output_dir)){
        die "$Usage";
}
if(!(-f $report_file)){
        print "$report_file is not exist\n";
        die "$Usage";
}
if(!(-d $output_dir)){
        print "$output_dir is not directory or is not exist\n";
        die "Usage";
}

$rfd = new FileHandle("$report_file");

while ($line =<$rfd>){

	if ($line =~ /^\s*(\w+)\/\s*\w*\s*\/\w+\/*\w*\s+\d+-\d+-\d+\s*\d+:\d+:\d+\s*$/){
		$msc_name=$1;
        }
	if ($line =~ /^\s*STARTED:\s*(\d{2})-(\d{2})-(\d{2})\s*AT\s*(\d{2}):(\d{2})\s*ENDED:\s*(\d{2})-(\d{2})-(\d{2})\s*AT\s*(\d{2}):(\d{2})/){
		$o=$i;
		$i++;
		$Iar_obj[$o]{'s_year'} = 2000+$1;
		$Iar_obj[$o]{'s_mon'}  = $2;
		$Iar_obj[$o]{'s_day'}  = $3;
		$Iar_obj[$o]{'s_hour'} = $4;
		$Iar_obj[$o]{'s_min'}  = $5;
		$Iar_obj[$o]{'scan_start_time'} = (2000+$1)."-$2-$3 $4:$5:00";
		$Iar_obj[$o]{'scan_stop_time'}  = (2000+$6)."-$7-$8 $9:$10:00";
	}
	if ($line =~ /^\s*DNAME=(\w+)\s+ONAME=(\w+)/){
		$Iar_obj[$o]{'dname'} = $1;
		$Iar_obj[$o]{'oname'} = $2;
	}
	if ($line =~ /^\s*DAY\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/){
		$Iar_obj[$o]{'call_attempts'}     = $1;
		$Iar_obj[$o]{'holding_time1'}     = $2;
		$Iar_obj[$o]{'holding_time2'}     = $3;
		$Iar_obj[$o]{'call_with_answer'}  = $4;
		$Iar_obj[$o]{'conversation_time'} = $5;
	}

}

close($rfd);

$wfd = new FileHandle(">$output_dir/iarstat.txt");
	
for($o=0;$o<$i;$o++){

	print $wfd "$Iar_obj[$o]{'scan_start_time'}\t$Iar_obj[$o]{'scan_stop_time'}\t";
	print $wfd "$Iar_obj[$o]{'s_year'}\t$Iar_obj[$o]{'s_mon'}\t$Iar_obj[$o]{'s_day'}\t";
	print $wfd "$Iar_obj[$o]{'s_hour'}\t$Iar_obj[$o]{'s_min'}\t";
	print $wfd "$Iar_obj[$o]{'dname'}\t$Iar_obj[$o]{'oname'}\t$Iar_obj[$o]{'call_attempts'}\t";
	print $wfd "$Iar_obj[$o]{'holding_time1'}\t$Iar_obj[$o]{'holding_time2'}\t";
	print $wfd "$Iar_obj[$o]{'call_with_answer'}\t$Iar_obj[$o]{'conversation_time'}\t$msc_name\n";

}

close($wfd);

$wfd = new FileHandle(">$output_dir/QETXT.INI");

	print $wfd "[Defined Tables]\n";
        print $wfd "iarstat.txt=IARTABLE\n\n\n";

        print $wfd "[IARTABLE]\n";
        print $wfd "FILE=iarstat.txt\n";
        print $wfd "TT=TAB\n";
        print $wfd "FLN=0\n";
        print $wfd "FIELD1=scan_start_time,VARCHAR,20,0,20,0,\n";
        print $wfd "FIELD2=scan_stop_time,VARCHAR,20,0,20,0,\n";
        print $wfd "FIELD3=s_year,NUMERIC,10,0,10,0,\n";
        print $wfd "FIELD4=s_mon,NUMERIC,10,0,10,0,\n";
        print $wfd "FIELD5=s_day,NUMERIC,10,0,10,0,\n";
        print $wfd "FIELD6=s_hour,NUMERIC,10,0,10,0,\n";
        print $wfd "FIELD7=s_min,NUMERIC,10,0,10,0,\n";
        print $wfd "FIELD8=dname,VARCHAR,20,0,20,0,\n";
        print $wfd "FIELD9=oname,VARCHAR,20,0,20,0,\n";
        print $wfd "FIELD10=call_attempts,NUMERIC,10,0,10,0,\n";
	print $wfd "FIELD11=holding_time1,NUMERIC,10,0,10,0,\n";
	print $wfd "FIELD12=holding_time2,NUMERIC,10,0,10,0,\n";
	print $wfd "FIELD13=call_with_answer,NUMERIC,10,0,10,0,\n";
	print $wfd "FIELD14=conversation_time,NUMERIC,10,0,10,0,\n";
	print $wfd "FIELD15=msc_name,VARCHAR,20,0,20,0,\n";

close($wfd);


exit 0;