-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPiTempLogger.sh
executable file
·116 lines (109 loc) · 2.8 KB
/
PiTempLogger.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
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
#!/bin/bash
rm -rf logcontainer
rm -rf *.tlog
OUTPUT="logcontainer"
echo -e "temp" >$OUTPUT
#LogFilename=$(<$OUTPUT)
#rm -rf $OUTPUT
#>$OUTPUT
#function removeActiveLog {
#LogToRemove=$(<$OUTPUT)
#read -p "Remove Existing Logs? (Y/N) " AnswerRemove
#if [ "$AnswerRemove" = "Y" ] || [ "$AnswerRemove" = "y" ] ; then
#rm -rf "$LogToRemove"
#performLog
#elif [ "$AnswerRemove" = "N" ] || [ "$AnswerRemove" = "n" ] ; then
#performLog
#else
#echo -e "Please press Y/y for Yes or N/n for No!!\e"
#removeActiveLog
#fi
#}
function cleanQuit {
read -p "Keep Logs? " keepLogs
if [ "$keepLogs" = "Y" ] || [ "$keepLogs" = "y" ] ; then
rm -rf logcontainer
elif [ "$keepLogs" = "N" ] || [ "$keepLogs" = "n" ] ; then
rm -rf *.tlog
rm -rf logcontainer
else
echo -e "Please press Y/y for Yes or N/n for No!!\e"
cleanQuit
fi
}
function setLogFilename {
dialog --title "Input Box" --backtitle "Temperature Logger" \
--inputbox "Enter log filename " 8 60 2>$OUTPUT
mainmenu
}
function viewLog {
LogFile=$(<$OUTPUT)
LogPrefix=$(ls -t $LogFile* | grep tlog | head -1)
if [ -z "$LogPrefix" ]
then
echo "Log file does not exist."
mainmenu
else
clear
cat $LogPrefix | less
mainmenu
fi
}
function performLog {
COUNTER=0
LogFilename=$(<$OUTPUT)
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
read -p "Set Log Total Time: " LogTotalTime
read -p "Set Log Period: " LogPeriod
#for i in {16..21} {21..16} ;
#do echo -en "\e[38;5;${i}mStart Logging every $LogPeriod for $LogTotalTime ...\e[0m" ; done ; echo
echo -e "Start Logging every $LogPeriod seconds for $LogTotalTime seconds ..."
while [ $COUNTER -lt $LogTotalTime ]; do
#echo Measurement $COUNTER is:
myout=$(vcgencmd measure_temp | cut -d'=' -f2 | cut -d"'" -f1)
#echo -e "Current Time is"
echo -e "Temperature at \e[104m$COUNTER\e[49m seconds is \e[41m$myout\xC2\xB0C\e[49m "
echo -e "Waiting $LogPeriod second(s)"
echo -e "$COUNTER \t $myout" >> $LogFilename.$current_time.tlog
sleep $LogPeriod
let COUNTER=COUNTER+$LogPeriod
done
#return to mainmenu
mainmenu
}
function mainmenu {
LogFilename=$(<$OUTPUT)
HEIGHT=15
WIDTH=40
CHOICE_HEIGHT=5
BACKTITLE="Temperature Logger"
TITLE="Logger Main Menu"
MENU="Choose one of the following options:"
OPTIONS=(1 "Run Temperature Log"
2 "Select Log Filename"
3 "View Log"
4 "Exit Logger")
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
case $CHOICE in
1)
performLog
;;
2)
setLogFilename
;;
3)
viewLog
;;
4)
cleanQuit
;;
esac
}
mainmenu