-
Notifications
You must be signed in to change notification settings - Fork 1
/
log2db.sh
executable file
·48 lines (34 loc) · 1.03 KB
/
log2db.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
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
PREFIX=<LOCAL DIRECTORY>
URL=<LOCAL URL WHERE ARE THE LOGS>
NPROCS=4 # 6
function process_day {
year=$1; month=$2; day=$3
d=$year$month$day
log=$URL/$year/$month/download.opensuse.org-$d-access_log.gz
if curl -sIf -o /dev/null "$log"; then
curl -s "$log" | gunzip | python log2db.py --dbenv $PREFIX/dbenv --db $d &> $PREFIX/logs/$d.txt
fi
}
# If we don't say anything, we get since the beginning until today (excluded)
SINCE=${1:-"2010-01-01"}
LAST=${2:-`date -d "tomorrow" +%Y-%m-%d`}
echo "Converting from [$SINCE to $LAST)"
# Store the # on concurrent procs
count=0
current=$SINCE
while [ "$current" != "$LAST" ]; do
# Extract date the components
year=`echo $current | cut -d'-' -f1`
month=`echo $current | cut -d'-' -f2`
day=`echo $current | cut -d'-' -f3`
echo "Converting $current ..."
count=$((count + 1))
( process_day $year $month $day ) &
if [ $((count % $NPROCS)) -eq 0 ]; then
wait
fi
# Next day
current=`date -d "$current +1 day " +%Y-%m-%d`
done
wait