don't delete anything
[zc] / gnuplot / calc-offset-filter.sh
1 #!/bin/sh
2
3 grep $1 ~/zc/subvision-numbers.txt | awk '{ print $2 }' > /tmp/pn.filter
4 shift
5
6 interval="1 day"
7 test ! -z "$1" && interval="$*"
8
9 cat calc-offset.sql | sed "s/90 days/$interval/" | psql -A -t -F' ' zc | grep -f /tmp/pn.filter > offset.txt.new
10 grep -v -f /tmp/pn.filter offset.txt > offset.txt.partial
11 cat offset.txt.partial offset.txt.new > offset.txt
12
13 exit 0
14
15 echo "Press enter to remove old data or ctrl+c to abort"
16 read wait_for_enter
17
18 in_pn=$( cat /tmp/pn.filter | tr '\n' ',' | sed 's/,$//' )
19 last_alarm=$( echo "select max(time) from zc where pn in ( $in_pn ) and alarm_axis > 0" | psql -A -t zc )
20 removed="removed_$( date +%Y_%m_%d )"
21 echo "last alarm at $last_alarm"
22 echo "create table $removed as select * from zc where pn in ( $in_pn ) and time <= '$last_alarm'" | psql zc
23 echo "delete from zc where _id in ( select _id from $removed )" | psql zc