summaryrefslogtreecommitdiffhomepage
path: root/bench/report.sh
blob: e007f7758c04e1203ab2bf521a1c08cbd8adcf4f (plain)
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
#!/bin/sh
# A report built the way a deployment script builds one: read a log line
# by line, count it by level and by hour, print the totals.  case, read,
# arithmetic and printf, which is the shape of most real scripts.
awk 'BEGIN {
    for (i = 0; i < 20000; i++) {
        lvl = (i % 7 == 0) ? "ERROR" : (i % 3 == 0) ? "WARN" : "INFO"
        printf "%02d:%02d:%02d %s job%d step%d\n", i % 24, i % 60, (i * 7) % 60, lvl, i % 40, i % 12
    }
}' >bench.tmp
errors=0
warns=0
night=0
while read -r stamp level rest; do
    case $level in
    ERROR) errors=$((errors + 1)) ;;
    WARN) warns=$((warns + 1)) ;;
    esac
    hour=${stamp%%:*}
    case $hour in
    [0-7]?) night=$((night + 1)) ;;
    esac
done <bench.tmp
rm -f bench.tmp
printf 'errors=%d warns=%d night=%d\n' "$errors" "$warns" "$night"