]> www.average.org Git - pulsecounter.git/blob - linux/store.awk
Notes on using sqlite3
[pulsecounter.git] / linux / store.awk
1 #!/usr/bin/awk
2
3 # (zcat /var/log/syslog.*.gz;cat /var/log/syslog.1 /var/log/syslog) \
4 # | grep 'pulsecounter: store:' > store.log
5 # then "awk -f store.awk store.log"
6
7 # Jan  1 11:49:00 pccross pulsecounter: store: "2,156"
8 # 1    2 3        4       5             6      7
9
10 BEGIN {
11   m["Jan"] = 1;
12   m["Feb"] = 2;
13   m["Mar"] = 3;
14   m["Apr"] = 4;
15   m["May"] = 5;
16   m["Jun"] = 6;
17   m["Jul"] = 7;
18   m["Aug"] = 8;
19   m["Sep"] = 9;
20   m["Oct"] = 10;
21   m["Nov"] = 11;
22   m["Dec"] = 12;
23   table[1] = "coldcnt";
24   table[2] = "hotcnt";
25 }
26
27 {
28   if ($1 ~ /Jan/) yr = 2016; else yr = 2015;
29   split($3, t, ":");
30   tstr = sprintf ("%04d %02d %02d %02d %02d %02d", yr, m[$1], $2, t[1], t[2], t[3]);
31   print tstr, $7;
32   tsstr = strftime("%Y-%m-%d %H:%M:%S", mktime(tstr), 1)
33   match($7, /"([12]),([0-9]+)"/, v)
34   print "insert into " table[v[1]] " values ('" tsstr "', " v[2] ");"
35 }