#!/usr/local/bin/perl
# raquick - report the last time each user logged in or out
#
# 94/11/28	Author: Carl Rigney; cdr@livingston.com
# 94/12/03	modified
# 96/09/27 	updated to work with RADIUS 2.0
#
# input files = /usr/adm/radacct/*/detail
# Currently must specify only one input file as an argument
#
# output format is username followed by hours:minutes:seconds
# dave            	   1:36:48

$/ = '';	# read paragraph at a time

while (<>) {
	next if /Acct-Session-Id = "00000000"/;
	$user = "\t";
	if (/User-Name = "([^"]+)"/) {
		$user = $1;
		$nas = "\t";
	}
	if (/NAS-IP-Address = (\S+)/ ||
	    /Client-Id = (\S+)/) {
		$nas = $1;
		$last{$user."\t".$nas} = substr($_,0,25);	# date
	}
}

for $usernas (sort keys %last) {
	printf "%-24s\t%s",$usernas,$last{$usernas};
}

