-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregler.sh
84 lines (69 loc) · 1.54 KB
/
regler.sh
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/sh
#
# ACHTUNG KEIN BASH Script, sondern dash/sh
#
OPENWBBASEDIR=/var/www/html/openWB
########## Re-Run as PI if not
USER=${USER:-`id -un`}
# [ "$USER" != "pi" ] && exec sudo -u pi "$0" -- "$@"
cd /var/www/html/openWB || exit 0
openwbDebugLog()
{
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
d1=$1
shift; shift;
echo "$timestamp $$ $d1 $*" >>/var/www/html/openWB/ramdisk/openWB.log
}
# Hal1
# debloggerip=""
debloggerip=${debloggerip:-192.168.208.1}
# echo $debloggerip
rlog() # rlog TAG Messages
{
if [ -n "$debloggerip" ] ; then
d=$1
shift;
logger --id=$$ -t $d -n $debloggerip -- $*
fi
}
TAG=SHED
REGEL=regel.sh
dspeed=${dspeed:-0}
#read ip<ramdisk/ipaddress 2>/dev/null
ip=${ip:-1.1.1.4}
sleeper=$(echo $ip | cut -d "." -f 4)
sleeper=$(( (sleeper % 10) -1 ))
sleep $sleeper
# dspeed=2
case $dspeed in
1)
ticksec=5
;;
2)
ticksec=20
;;
3)
ticksec=60
;;
*)
ticksec=10
;;
esac
openwbDebugLog "MAIN" 1 "SHED regler starti as $USER (dspeed:$dspeed ticksec:$ticksec)"
loop=0
while [ "$loop" -lt 60 ] ; do
if pidof -xs $REGEL >/dev/null ; then
rlog $TAG "$REGEL is still running, skip (loop:$loop)"
openwbDebugLog "MAIN" 0 "SHED Skip $REGEL, is still running (loop:$loop)"
else
openwbDebugLog "MAIN" 1 "SHED Start $REGEL & (loop:$loop)"
env -i - HOME=/home/pi ./$REGEL >>ramdisk/openWB.log 2>&1 &
fi
# rlog $TAG sleeps for $ticksec
loop=$(( loop + ticksec ))
if [ $loop -lt 60 ] ; then
sleep $ticksec
fi
done
openwbDebugLog "MAIN" 2 "SHED Exit regler"
exit 0