#!/usr/bin/perl # # Perl Script to Process Ipass cdr.txt files. # # By: David A. Flanigan # No Warrnety provided or implied, use at your own risk. # Free for any use. Please send improvements back to dave@flanigan.net # E-mail dave@flanigan.net with questions on modifying this script. # http://www.flanigan.net/scripts # # File field format: # trans id, billing code, user id, auth domain, descript, GMT, Local Time, Session length (seconds), # Billing Rate (per min), Net Billing, Access Type, Service Type. # use Number::Format qw(:subs); if ($ARGV[0] eq "") { print "usage: ipassproc.pl \n"; exit(1); } open (FILE, "$ARGV[0]"); while ( ) { $callnum++; chop; #Stupid way to seperate values, lets strip and replace "," with a simple | for easier process. $_ =~ s/\",\"/|/g; #Abvove leaves us with a preceding and trailing " - lets wack-em. $_ =~ s/\"//g; #Ok, now we can split into variables. ($bid, $bcode, $user, $adom, $descrip, $gmtime, $loctime, $slength, $brate, $netbill, $atype, $stype) = split (/\|/, $_); # Why would you have session length in seconds but the billing ratge in Hours??? $sbrate = $brate/3600; # OK, now process the line # First, incriment user hash $calls{$user}++; $costs{$user} = $costs{$user} + $netbill; #Count up the total billing $totalbill = $totalbill + $netbill; #find long calls if ($slength > 36000) { #compute overage $netcred = (($slength - 36000)*$sbrate); #Augment Counters $longcred = $longcred + $netcred; $longcred = sprintf("%.2f", $longcred); $longnum++; $netcred = format_number($netcred, 2); print "$user, $bid, $netcred\n"; } } close FILE; #post processing $totalbill = sprintf("%.2f", $totalbill); $totalbill = format_number($totalbill, 2); #output print "Total Invoice: $totalbill\n"; print "There where $longnum long calls totalling $longcred\n"; exit(0);