-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.bash
59 lines (47 loc) · 1.68 KB
/
temp.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
#!/bin/bash
FILENAME="temp.txt"
START_TIME="00:00:00"
# enter in seconds
INTERVAL=900
# readjust to sync time. enter in iteration. better keep time under so it works everyday
READJUST_TIME_EVERY=3
# infinite loop
while true;
do
# help keep pi keep track of time properly. start checking time from this iteration
KEEP_TIME_SYNC=4
# starts measuiring temperature from midnight
if [ $(date +"%T") = $START_TIME ];then
# clears previous days info
echo -ne "" > $FILENAME
number_of_loop=`expr $((( 60 * 60 * 24 ) / $INTERVAL ))`
# check for every hour
for (( i=1; i<=$number_of_loop; i++ ))
do
# enter local time
echo -ne $(date +"%T") >> $FILENAME
echo -ne " - " >> $FILENAME
# enter temperature
echo -ne $(/opt/vc/bin/vcgencmd measure_temp) >> $FILENAME
# cpu speed
CURR_CPU=$(sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
MIN_CPU=$(sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq)
MAX_CPU=$(sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq)
CURR_CPU_PERCENT=`expr $(((( CURR_CPU - MIN_CPU ) / (MAX_CPU - MIN_CPU )) * 100))`
echo -ne " - Current CPU usage: $CURR_CPU_PERCENT% - Current CPU speed: $CURR_CPU kHz\n" >> $FILENAME
# sometimes pi adds a second. This helps metigate its effects
if [ $KEEP_TIME_SYNC == $i ];then
delay=`expr $(( $INTERVAL - 1 ))`
KEEP_TIME_SYNC=`expr $(( KEEP_TIME_SYNC + READJUST_TIME_EVERY ))`
else
delay=$INTERVAL
fi;
sleep $delay
done
# show script has completed running
echo -ne "EOF" >> $FILENAME
else
# checks if correct time every second
sleep 1
fi;
done