#!/bin/bash BASE_DIR=/tmp/domain_logs dateToStamp () { if [ ${#1} -eq 19 ]; then date --utc --date "$1" +%s; else echo 0 fi } formatDate () { echo $1 | awk 'BEGIN { \ dict["Jan"]=1; \ dict["Feb"]=2; \ dict["Mar"]=3; \ dict["Apr"]=4; \ dict["May"]=5; \ dict["Jun"]=6; \ dict["Jul"]=7; \ dict["Aug"]=8; \ dict["Sep"]=9; \ dict["Oct"]=10; \ dict["Nov"]=11; \ dict["Dec"]=12 \ } { \ split(substr($1, 2), a, /[\\\/:]+/); \ print a[3] "-" dict[a[2]] "-" a[1] " " a[4] ":" a[5] ":" a[6] \ }' } for file in `ls $BASE_DIR/*`; do from=$(formatDate `head -1 $file | awk '{print($4)}'`) to=$(formatDate `tail -1 $file | awk '{print($4)}'`) stamp_from=$(dateToStamp "$from") stamp_to=$(dateToStamp "$to") total_time=$(($stamp_to-$stamp_from)) bytes=`cat $file | awk '{a+=$10}END{print a}'` kbytes=$((bytes/1024)) mbytes=$((kbytes/1024)) echo "$mbytes MB | \ $kbytes KB | \ $bytes Bytes | \ From: $from ($stamp_from) | \ To: $to ($stamp_to) | \ $total_time secs | \ ${file:${#BASE_DIR}+1}" done \ | sort -nb