how-to_‎ > ‎

Extract matching packets from freeRADIUS radius accounting detail

posted May 20, 2016, 12:32 AM by Daniele Albrizio   [ updated May 20, 2016, 12:32 AM ]

Dirty but working-with-large-files script to multiline grep out interesting lines from detail files.

Usage examples:

callingstationid extraction:

$ cat detail | grepradacct "00:0e:ff:ab:cd:ef"

username extraction:

$ cat detail | grepradacct "jane@ucla.edu"

$ grepradacct "jane@ucla.edu" detail


Content of grepradacct script:

#!/bin/sh
GREPSTRING=$1

if [ $2 ]; then
 echo Results in $2 >&2
 cat $2 |\
 awk -F'\n' 'BEGIN {RS='\n\n'; ORS='\t'; OFS='\t';} { for (i=1; i<=NF; i++) print $i } { print "\n\n" }' |\
 grep -a "$GREPSTRING" |\
 awk -F'\t' 'BEGIN {OFS='\n';} {print "\n" $1; for (i=2; i<=NF; i++) print "\t" $i "" }'
else
 cat - |\
 awk -F'\n' 'BEGIN {RS='\n\n'; ORS='\t'; OFS='\t';} { for (i=1; i<=NF; i++) print $i } { print "\n\n" }' |\
 grep -a "$GREPSTRING" |\
 awk -F'\t' 'BEGIN {OFS='\n';} {print "\n" $1; for (i=2; i<=NF; i++) print "\t" $i "" }'
fi

Comments