From 89ef05875226c033437555150a1cf7b3fbfe33ab Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Fri, 1 Jan 2016 17:24:11 +0300 Subject: [PATCH] script to repopulate database from syslog --- linux/store.awk | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 linux/store.awk diff --git a/linux/store.awk b/linux/store.awk new file mode 100644 index 0000000..69c8b0a --- /dev/null +++ b/linux/store.awk @@ -0,0 +1,35 @@ +#!/usr/bin/awk + +# (zcat /var/log/syslog.*.gz;cat /var/log/syslog.1 /var/log/syslog) \ +# | grep 'pulsecounter: store:' > store.log +# then "awk -f store.awk store.log" + +# Jan 1 11:49:00 pccross pulsecounter: store: "2,156" +# 1 2 3 4 5 6 7 + +BEGIN { + m["Jan"] = 1; + m["Feb"] = 2; + m["Mar"] = 3; + m["Apr"] = 4; + m["May"] = 5; + m["Jun"] = 6; + m["Jul"] = 7; + m["Aug"] = 8; + m["Sep"] = 9; + m["Oct"] = 10; + m["Nov"] = 11; + m["Dec"] = 12; + table[1] = "coldcnt"; + table[2] = "hotcnt"; +} + +{ + if ($1 ~ /Jan/) yr = 2016; else yr = 2015; + split($3, t, ":"); + tstr = sprintf ("%04d %02d %02d %02d %02d %02d", yr, m[$1], $2, t[1], t[2], t[3]); + print tstr, $7; + tsstr = strftime("%Y-%m-%d %H:%M:%S", mktime(tstr), 1) + match($7, /"([12]),([0-9]+)"/, v) + print "insert into " table[v[1]] " values ('" tsstr "', " v[2] ");" +} -- 2.39.2