+bin/upsc-log,+bin/upsc-log-diff
[nethome.git] / bin / upsc-log
diff --git a/bin/upsc-log b/bin/upsc-log
new file mode 100755 (executable)
index 0000000..7298a39
--- /dev/null
@@ -0,0 +1,38 @@
+#! /bin/bash
+renice >/dev/null +19 -p $$
+ionice -c3 -p $$
+t=/tmp/upsc-log.$$
+rm -f $t $t.*
+log=/var/log/upsc.log
+exec >>$log 2>&1
+while sleep 1;do
+  date --iso=seconds >$t.t
+  upsc eaton &>$t
+  if grep -q '^ups.status: OL$' $t && grep -q '^battery.charge: 100$' $t;then
+    rm -f $t.bad $t.bad.t
+    if [ ! -e $t.good ];then
+      cat $t.t $t;echo
+      sync -d $log
+    fi
+    mv -f $t.t $t.good.t
+    mv -f $t   $t.good
+    rm -f /tmp/upsc-smsed
+    continue
+  fi
+  if [ ! -e /tmp/upsc-smsed ];then
+    touch /tmp/upsc-smsed
+    date --iso=seconds|mail -s "upsc-log $(hostname)" jankratochvil@vodafonemail.cz
+  fi
+  if [ -e $t.good ];then
+    cat   $t.good.t $t.good;echo
+    sync -d $log
+    rm -f $t.good.t $t.good
+  fi
+  if [ -e $t.bad ] && cmp -s $t $t.bad;then
+    continue
+  fi
+  cat $t.t $t;echo
+  sync -d $log
+  mv -f $t.t $t.bad.t
+  mv -f $t   $t.bad
+done