Pejman Moghadam / Scripts

Freeradius stanzim-moghararat logger

Public domain


#!/bin/bash
DATE="2009-01-01"
PASS="123456"
DB="radius"
TMP="tmp.log"
LOG="${DATE}.csv"

mysql -p${PASS} $DB -e "
  SELECT
    AcctStartTime,AcctStopTime,FramedIPAddress,CallingStationId
  FROM
    radacct
  WHERE
    date(AcctStartTime)='${DATE}'
  OR
    date(AcctStopTime)='${DATE}'
  "  |\
egrep -v '^AcctStartTime' |\
awk '{if ($6 == "") print$1" "$2","$3" "$4",,"$5; else print$1" "$2","$3" "$4","$5","$6}' > ${LOG}
sed -i -e "s/,242/,/" ${LOG}
awk -F ',' '{print$1","$2","$3",242"$4}' ${LOG} > ${TMP}
mv ${TMP} ${LOG}
sed -i -e 's,-,/,g' ${LOG}

BY: Pejman Moghadam
TAG: tanzim, sed, awk, bash-script, bash
DATE: 2010-01-02 19:10:32


Pejman Moghadam / Scripts [ TXT ]