-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathSensordata_loop.bash
executable file
·160 lines (145 loc) · 3.82 KB
/
Sensordata_loop.bash
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
# set -veux
q="'"
Q='"'
cxname=${1:-}
if [[ x$cxname == x ]] ; then
echo "$0: please specify CX to start and monitor"
exit 1
fi
quit_now=0
tagname="$cxname"
temps_flag=/tmp/monitor_temps
chart_flag=/tmp/monitor_chart
run_flag=/tmp/monitor_run
begintime=`date "+%Y-%m-%d %H:%M"`
checkon() {
local interval=$1
local flag=$2
if [[ x$1 == x ]]; then
echo "checkon: no interval, bye"
ctrl_c
exit 1
fi
if [[ x$2 == x ]]; then
echo "checkon: no flag file name, bye"
ctrl_c
exit 1
fi
while (( interval >= 0 )); do
sleep 1
[ ! -f $flag ] && return
[ ! -f $run_flag ] && return
interval=$((interval- 1))
done
}
countdown() {
local left=$1
while (( left >= 0 )); do
if (( quit_now == 1 )) || [ ! -f $run_flag ]; then
break
fi
printf "\r%d..." $left
sleep 1
left=$((left - 1))
done
}
start_cx() {
if [[ x$1 == x ]]; then
echo "start_cx: no CX name, bye"
ctrl_c
exit 1
fi
for cx in "$@"; do
echo "Starting $cx..."
/home/lanforge/scripts/lf_firemod.pl --mgr localhost --quiet yes --action do_cmd --cmd \
"set_cx_state default_tm $cx RUNNING"
done
}
stop_cx() {
/home/lanforge/scripts/lf_firemod.pl --mgr localhost --quiet yes --action do_cmd --cmd \
"set_cx_state ALL ALL STOPPED"
}
ctrl_c () {
quit_now=1
[ ! -f $run_flag ] && return
echo -n "cleaning up..."
stop_cx
rm -f $temps_flag
rm -f $chart_flag
rm -f $run_flag
echo "done"
}
trap ctrl_c INT
monitor_temps() {
if [[ x$1 == x ]]; then
echo "monitoring_temps: no monitoring duration"
exit 1
fi
echo "monitoring temps every $1"
if [ ! -x /home/lanforge/scripts/sensorz.pl ]; then
echo "no sensorz.pl, bye"
ctrl_c
exit 1
fi
touch $temps_flag
while [ -f $temps_flag ] && [ -f $run_flag ]; do
if (( quit_now == 1 )); then
echo "monitoring_temps ending"
break;
fi
/home/lanforge/scripts/sensorz.pl | logger -t "$tagname"
checkon $1 $temps_flag
done
echo "done monitoring temps"
}
monitoring_chart() {
if [[ x$1 == x ]]; then
echo "monitoring_chart: no monitoring duration"
ctrl_c
exit 1
fi
if [ ! -x /home/lanforge/sensor_chart.bash ]; then
echo "no sensor_chart.bash, bye"
ctrl_c
exit 1
fi
echo "charting temps every $1"
touch $chart_flag
while [ -f $chart_flag ] && [ -f $run_flag ]; do
checkon $1 $chart_flag
if (( quit_now == 1 )) || [ ! -f $run_flag ]; then
echo "monitoring_chart ending"
break
fi
echo " sensor_chart.bash $tagname $q${begintime}$q"
/home/lanforge/sensor_chart.bash "$tagname" "${begintime}" || {
echo "FAILED TO GENERATE CHART"
ctrl_c
exit 1
}
done
now=`date +%Y-%m-%d_%H.%M.%S`
mv ~/Documents/sensordata.${tagname}.png ~/Documents/sensordata.${tagname}.${now}.png
echo "done charting temps see `pwd`/sensordata.${tagname}.${now}.png"
}
cd ~/Documents/
# stop all existing connections
stop_cx
touch $run_flag
monitor_temps ${SENS_INTERVAL_SEC:-30} & # usually 30s
# countdown $(( 60 * 1 )) # realistic cooldown time is about 10m
countdown ${PRECOOL_SEC:-60} # realistic cooldown time is about 10m
start_cx $@
default_chart_interval_sec=$((60 * 2))
monitoring_chart ${CHART_INTERVAL_SEC:-$default_chart_interval_sec} & # usually 2m
default_dur_sec=$(( 60 * 60 * 45 ))
countdown ${TEST_DUR_SEC:-$default_dur_sec} # usually 45m
stop_cx
echo "cooling off..."
countdown ${CHART_INTERVAL_SEC:-$default_chart_interval_sec} # needs to be as long as charting interval
echo "stopping monitoring..."
rm -f $temps_flag $chart_flag $run_flag
#countdown ${CHART_INTERVAL_SEC:-$default_chart_interval_sec} # needs to be as long as charting interval
echo done
#