Re: Parsing Detail file

Dave Kennedy (davek@muscle.net)
Mon, 28 Oct 1996 18:20:58 -0500 (EST)

Network Operations Center writes...
> On Mon, 28 Oct 1996, Dave Kennedy wrote:
> > Network Operations Center writes...
> > > Does anyone have a script (or is willing to whip one up real quick) in
> > > perl, that will pull just todays records from the master detail file.
> > > I am not quite good enuf at perl to write it myself (wiithout it being
> > > real ugly and probably way too long). PLEASE.....
> >
> > How about:
> >
> > lineparser | grep '10/01/96'
> >
>
> oops, I spoke too soon....
>
> Normally that would work, but I need to keep it in the standard format so
> it will work with my other scripts. Its probably a two-liner for someone
> who knows what they are doing.

OK, how about this. The way to run it is:

$ rlog.date "`date '+%b. %e ..:..:.. %Y`"

Let me know what you think. Caveat - No warranty, etc.

If somebody knows how to format the date above using perl, let
me know. Or even better, how do you get the output from a shell
command in perl available to the program?

davek

Here's the source:

#!/usr/bin/perl
########################################################################
# $Id: rlog.date,v 1.2 1996/10/28 23:14:27 root Exp $
#
# DESCRIPTION
# Prints raw RADIUS detail file for a specific date
#
# USAGE
# rlog.date "`date '+%b. %e ..:..:.. %Y`" <detailfile>
#
# The funky date command is to get the date in the right
# format, but not worry about the time. The above gives today's
# information. Different input would give different days.
#
#
# HISTORY
# Written 10/28/96 by Dave Kennedy <davek@muscle.net>
#
# I wrote this because I felt like it. :)
#
########################################################################

########################################################################
# Get the user name from the command line
$pat_date = $ARGV[0];

# Default detail file to use
$file = "/usr/adm/radacct/pm1/detail";

# Get the detail file specified on the command line if one given
if ($ARGV[1] ne "")
{
$file = $ARGV[1];
}

# Open the detail file
open(IN, $file) || die "Could not open file $file\n";

# Initialize some values
$pat_user = sprintf("User-Name = \"%s\"", $user);

$lookahead = <IN>;
while ($_ = read_record())
{
# chomp;
if (!length($_)) {
next;
}

if ($_ =~ $pat_date) {
print;
}

}

exit;

# Make the multi-line RADIUS record into one string
sub read_record {
$thisline = $lookahead;
LINE:
while ($lookahead = <IN>) {
if ($lookahead =~ /^[ \t]/) {
$thisline .= $lookahead;
}
else {
last LINE;
}
}
return $thisline;
}

-- 
| Dave Kennedy (davek@muscle.net)             Voice: 770-368-1514 |
| Multi-User Systems, Inc.      Putting MUSCLE in Internet Access |