Cover V06, I07
Article
Figure 1
Figure 2
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5
Listing 6

jul97.tar


Listing 4: Generate table by user name

#!/usr/local/bin/perl
#
# Listing 4 - Generates table by user name
#

require "ctime.pl";

sub timeconvert {

$hours = int($_[0] / 3600);
$minutes = int(( $_[0] % 3600 ) / 60);
$seconds = $_[0] - ($hours * 3600) - ($minutes * 60);

}

$firstuser = "";
$tconnect = 0;
$MAXCON = 0;
$i = 0;

$today = &ctime(time);

open(ULOG, "@ARGV")
|| die "Can't open log file : $!\n";

while ($logrec = <ULOG>) {

( $i1, $i2, $i3, $i4, $i5, $i6, $i7,
$i8, $i9, $i10, $i11, $i12, $i13, $i14, $i15 ) = \
split(/[      ]+/, $logrec);

$username[$i] = "$i6";
$linename[$i] = "$i8";
$month[$i] = $i1;
$day[$i] = $i2;
$connect[$i] = $i14;

if ( "$i6" eq "root" ) {
$i--;
} else {

$tconnect += $connect[$i];

if ( $connect[$i] > $MAXCON ) {
$MAXCON = $connect[$i];
}

$i++;

}

}


printf "<HEAD><TITLE> RAS Utilization Report - 'squid'</TITLE></HEAD>\n";
printf "<BODY>\n";
printf "<H1>RAS Utilization Report - User Detail - 'squid'</H1>\n";

printf "<TABLE BORDER ALIGN=\"CENTER\" CELLSPACING=\"3\" \
CELLPADDING=\"8\">\n";
printf "<TH>User Name</TH><TH>Connections</TH><TH>Total Connect \
Time</TH><TH>Avg. Con. Time</TH><TH>Max. Con. Time</TH>\n";


$firstuser = $username[0];
$usercount = 1;
$LMAXCON = 0;

for ( $j = 0; $j < $i; $j++ ) {


if ("$username[$j]" eq "$firstuser") {

$jc++;
$jrt += $connect[$j];

if ( $connect[$j] > $LMAXCON ) {
$LMAXCON = $connect[$j];
}


}

else {

$usercount++;
&timeconvert($jrt);

if ( $jc < 2 ) {

printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"green\ \
">%-12s</TH><TD>%4d</TD><TD>%03d:%02d:%02d</TD> \
</FONT>",$firstuser,$jc,$hours,$minutes,$seconds;
} else {

printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-12s</TH><TD>%4d</TD><TD>%03d:%02d:%02d</TD> \
</FONT>",$firstuser,$jc,$hours,$minutes,$seconds;

}


if ( $jc > 1 ) {

&timeconvert($jrt/$jc);
printf "<TD>%03d:%02d:%02d</TD>",$hours, $minutes, $seconds;

&timeconvert($LMAXCON);
printf "<TD>%03d:%02d:%02d</TD>\n",$hours, $minutes, $seconds;

} else {
printf "\n";
}


$jc = 1;
$jrt = $connect[$j];

$firstuser = $username[$j];
$LMAXCON = 0;

if ( $connect[$j] > $LMAXCON ) {
$LMAXCON = $connect[$j];
}

}
}

&timeconvert($jrt);


if ( $jc < 2 ) {

printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"green\ \
">%-12s</TH><TD>%4d</TD><TD>%03d:%02d:%02d</TD></FONT> \
",$firstuser,$jc,$hours,$minutes,$seconds;
} else {

printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-12s</TH><TD>%4d</TD><TD>%03d:%02d:%02d</TD></FONT>" \
,$firstuser,$jc,$hours,$minutes,$seconds;

}


if ( $jc > 1 ) {

&timeconvert($jrt/$jc);
printf "<TD>%03d:%02d:%02d</TD>",$hours, $minutes, $seconds;

&timeconvert($LMAXCON);
printf "<TD>%03d:%02d:%02d</TD>\n",$hours, $minutes, $seconds;

} else {
printf "\n";
}

printf "</TABLE>\n";

printf "<p>\n<p>\n";

printf "<TABLE BORDER ALIGN=\"CENTER\" CELLSPACING=\"3\" \
CELLPADDING=\"8\">\n";
printf "<TH>Summary Information</TH><TH><TH></TH>\n";

printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\">%-18s</TH><TD>%6d</TD></FONT>","Total Connections",$i;
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\">%-18s</TH><TD>%6d</TD></FONT>","Number of Unique Users",$usercount;

&timeconvert($tconnect);
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-18s</TH><TD>%04d:%02d:%02d</TD></FONT>", \
"Total Connect Time",$hours,$minutes,$seconds;

&timeconvert($MAXCON);
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-18s</TH><TD>%03d:%02d:%02d</TD></FONT>", \
"Maximum Connect Time",$hours,$minutes,$seconds;

&timeconvert($tconnect/$i);
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-18s</TH><TD>%02d:%02d:%02d</TD></FONT>", \
"Average Connect Time",$hours,$minutes,$seconds;

printf "</TABLE>\n";

printf "<HR>\n";
printf "<P><!-- hhmts start -->Last modified: %s <!-- hhmts end -- \
></P>\n",$today;
printf "</BODY>\n";

# End of File