-
Notifications
You must be signed in to change notification settings - Fork 0
/
topeni
executable file
·84 lines (74 loc) · 2.33 KB
/
topeni
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#KOTELPATH='/root/bin'
KOTELPATH='/root/unin-kotel'
DRYRUN=''
LOW='23'
HIGH='24'
TIME="60"
function print_help {
echo "Usage:"
echo " $(basename $0) [-h|-d] [<low> [<high>]]"
echo " -h ... print this help"
echo " -d ... dry run; just tell me what you wanna do"
echo " -t ... number of seconds between runs (default is 60)"
echo " low ... the low temperature limit (default is 23)"
echo " high ... the upper temperature limit (default is <low> or 24 if <low> is not defined)"
}
# Parse arguments
L=''
while [[ $# -ne 0 ]]; do
case ${1} in
-h)
print_help
exit 0
;;
-t|--time)
shift
TIME="${1}"
;;
-d|--dry)
DRYRUN='YES'
;;
[0-9]|[0-9][0-9])
[[ -z "${L}" ]] && \
{ LOW="${1}"; HIGH="${1}"; L='x'; } || \
HIGH="${1}"
;;
*)
echo "Invalid parameter ${1}"
exit 1
;;
esac
shift
done
NUMRE='^[-0-9]+$'
while true; do
STATUS="$( ${KOTELPATH}/kotel status)" || { echo 'Error getting the current kotel status'; sleep 1; continue; }
CURRENT="$( ${KOTELPATH}/current)" || { echo 'Error getting the current kotel temperature'; sleep 1; ${KOTELPATH}/kotel manual; continue; }
[[ ${CURRENT} =~ ${NUMRE} ]] || { echo "Invalid value received as a temperature >>${CURRENT}<<"; sleep 1; continue; }
T=$(( ${CURRENT} / 1000 )) || { echo "Error converting temperature"; sleep 1; continue; }
NEWSTATUS=''
[[ ${T} -gt ${HIGH} ]] && NEWSTATUS='stopped'
[[ ${T} -lt ${LOW} ]] && NEWSTATUS='started'
[[ -z "${NEWSTATUS}" ]] && NEWSTATUS="${STATUS}"
date "+%Y-%m-%d %H:%M:%S"
echo Temp: $T"."$(echo $CURRENT | tail -c 3)
echo Range: $LOW".00" " - " $HIGH".99"
if [[ "$NEWSTATUS" = "$STATUS" ]]; then
echo Status: $STATUS
else
echo Status: $STATUS " -> " $NEWSTATUS
fi
if [[ "${NEWSTATUS}" = "${STATUS}" ]]; then
: #echo "Kotel already in required state"
else
# echo "Switching kotel to status ${NEWSTATUS}"
[[ -z "${DRYRUN}" ]] && \
${KOTELPATH}/kotel ${NEWSTATUS} || \
echo "Dry run: ${KOTELPATH}/kotel ${NEWSTATUS}"
fi
sleep ${TIME}
echo
done
exit 0
#EOF