-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgenerate_radius_user_report.sh
36 lines (27 loc) · 1.09 KB
/
generate_radius_user_report.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Purpose : Extract Data of last one month from radius logs
Log_Path="/var/log/radius/"
Last_Month=$( date --date="$(date +%Y-%m-15) -1 month" +%b )
OutPut="/tmp/radius_users_$(date +%F).csv"
temp1=$(mktemp)
cd $Log_Path || exit 1
for log in $(find . -type f -iname "*log*" )
do
[[ $log =~ '.gz' ]] && CAT=zcat || CAT=cat
$CAT $log | while read -a line
do
[[ ${line[@]} =~ $Last_Month ]] || break
if [[ ${line[@]} =~ "Login OK" ]]
then
Date="${line[@]::5}"
User=${line[9]}
IP=${line[${#line[@]} - 1 ]%\)}
printf "%s,%s,%s\n" "${Date}" $User $IP | tee -a ${OutPut}
echo "$User" >> $temp1
fi
done
done
Total_Uniq_User=$(sort $temp1 | uniq | wc -l)
printf "%s,%s\n" "Total_Uniq_User" $Total_Uniq_User | tee -a ${OutPut}
echo "Report Generated at \"${OutPut}\""
rm ${temp1}