dhowells
18th September 2009, 21:32
Hello. I am at a site that has a tremendous amount of customizations. E.g., 1200+ custom sessions in td package alone; while environment is c4 and only 2 companies.

We are in the process of migrating to a new server. I feel this would be a good opportunity to do some housecleaning. Are there any easy ways to determine the usage history of a session, report, etc.

Any ideas will be appreciated.

Dan

dave_23
18th September 2009, 21:54
you'd have to turn on user history. it logs all the sessions that a user touches.

Dave

dhowells
18th September 2009, 22:00
That's what i was afraid of. our current file is size 277640579. Any ideas how to make that into smaller files for review? I can create a script to start parsing it out periodically from here on out.

thanks.

dave_23
19th September 2009, 02:36
"split" should be able to chunk up the file into small enough pieces to work with

a perl program would be a good idea too.

Dave

dave_23
19th September 2009, 05:22
This outta do it.

usage: session_stat.pl [<flags>] [<file>]
Flags: -c output by company
-u output by user
-s output by session

Dave



#!/usr/bin/perl

use strict;

my ($filename,%stat_hash,%user_hash, %sess_hash, $rec);

$filename = defined($ARGV[1]) ? $ARGV[1] : 'TIME.HIS';

open TIME_HIS, "< $filename" or die "Can't read $filename: $!";

while ( defined ( my $line = <TIME_HIS> ) ) {
chomp;
my ($company,$userid,$session,$s_day,$s_month,$s_year,$s_hour,
$s_min,$e_day,$e_month,$e_year,$_hour,$e_min) = split(/\|/,$line);
$sess_hash{$session}{'count'} = defined($sess_hash{$session}{'count'}) ? $sess_hash{$session}{'count'} + 1 : 0 ;
$stat_hash{$session}{$company}{'count'} = defined($stat_hash{$session}{$company}{'count'}) ? $stat_hash{$session}{$company}{'count'} + 1 : 0 ;
$user_hash{$userid}{$session}{'count'} = defined($user_hash{$userid}{$session}{'count'}) ? $user_hash{$userid}{$session}{'count'} + 1 : 0 ;
}

close TIME_HIS;

if ( $ARGV[0] eq "-c" ){
print_sessions_by_company(%stat_hash);
}
elsif ( $ARGV[0] eq "-u" ){
print_sessions_by_user(%user_hash);
}
else{
print_sessions(%sess_hash);
}

sub print_sessions {
my $rec;
for $rec ( sort keys %sess_hash ) {
print $rec, " ", $sess_hash{$rec}{'count'}, "\n";
}
}

sub print_sessions_by_company {
my ($rec, $rec2);
for $rec ( sort keys %stat_hash ) {
for $rec2 ( keys %{ $stat_hash{$rec} } ) {
print $rec, " ", $rec2, " ", $stat_hash{$rec}{$rec2}{'count'}, "\n";
}
}
}

sub print_sessions_by_user {
my ($rec, $rec2);
for $rec ( sort keys %user_hash ) {
for $rec2 ( keys %{ $user_hash{$rec} } ) {
print $rec, " ", $rec2, " ", $user_hash{$rec}{$rec2}{'count'}, "\n";
}
}
}