+.config/yt-dlp.conf
[nethome.git] / bin / upsc-log
1 #! /bin/bash
2 renice >/dev/null +19 -p $$
3 ionice -c3 -p $$
4 t=/tmp/upsc-log.$$
5 rm -f $t $t.*
6 log=/var/log/upsc.log
7 exec >>$log 2>&1
8 while sleep 1;do
9   date --iso=seconds >$t.t
10   upsc eaton &>$t
11   if grep -q '^ups.status: OL$' $t && grep -q '^battery.charge: 100$' $t;then
12     rm -f $t.bad $t.bad.t
13     if [ ! -e $t.good ];then
14       cat $t.t $t;echo
15       sync -d $log
16     fi
17     mv -f $t.t $t.good.t
18     mv -f $t   $t.good
19     rm -f /tmp/upsc-smsed
20     continue
21   fi
22   if [ ! -e /tmp/upsc-smsed ];then
23     touch /tmp/upsc-smsed
24     date --iso=seconds|mail -s "upsc-log $(hostname)" jankratochvil@vodafonemail.cz
25   fi
26   if [ -e $t.good ];then
27     cat   $t.good.t $t.good;echo
28     sync -d $log
29     rm -f $t.good.t $t.good
30   fi
31   if [ -e $t.bad ] && cmp -s $t $t.bad;then
32     continue
33   fi
34   cat $t.t $t;echo
35   sync -d $log
36   mv -f $t.t $t.bad.t
37   mv -f $t   $t.bad
38 done