Created
August 30, 2012 15:21
-
-
Save navasvarela/3530716 to your computer and use it in GitHub Desktop.
parse log file and get times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOGFILE=logs/802-1x.log | |
BEGIN_LOG="START OUTBOUND" | |
END_LOG="END OUTBOUND" | |
rm -f begins.log | |
rm -f ends.log | |
rm -f unparseable.log | |
rm -f radius_times.csv | |
# Extract begin times | |
cat $LOGFILE | grep "$BEGIN_LOG" >> begins.log | |
# Extract end times | |
cat $LOGFILE | grep "$END_LOG" >> ends.log | |
while read line | |
do | |
#echo -e "BEFORE -"$line | |
trid=$(echo $line | awk '{print substr($6,2, index($6,"]")-2)}') | |
#echo "AFTER - "$line | |
if [ -z $trid ] | |
then | |
echo $line >> unparseable.log | |
else | |
begin_time=`echo $line | awk '{print $2}'` | |
end_time=$(cat ends.log | grep $trid | head -1 |awk '{print $2}') | |
unix_end_time=$(date -u -d $end_time +%s.%N) | |
unix_begin_time=$(date -u -d $begin_time +%s.%N) | |
diff=`echo $unix_end_time - $unix_begin_time | bc` | |
if [ $(bc <<< "$diff-0") > 0 ] | |
then | |
echo $trid,$diff >> radius_times.csv | |
else | |
echo "Exception in TRID: "$trid | |
fi | |
fi | |
done < begins.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment