I'm trying to make this temperature log in Raspberry Pi happen (though some of the code did not work therefore I used slightly diff. solutions):
https://www.raspberrypi.org/learning/temperature-log/worksheet/
I'm stuck with writing the results in a file. I want to create a file that's name contains the actual date, e.g. temperature_log_2016_08_13.txt
When running the script I get an ambiguous redirection error each time lines with the echo commands execute. I tried all sort of combinations with quotes, double-quotes, no quotes. Pls advice.
#!/bin/bash
timestamp() {
date +%F_%H-%M-%S
}
temperature() {
/opt/vc/bin/vcgencmd measure_temp
}
temp=$(temperature)
temp2=${temp:5:9}
echo Temperature Log_$(date) >/home/pi/logs/temperature_log_$(date).txt
for i in {1..5}
do
echo ${temp2} $(timestamp) >>/home/pi/logs/temperature_log_$(date).txt
sleep 1
done
UPDATE: by putting the file name between quotation marks, as advised below, the ambiguous redirect error is gone, but instead the script produces 5 files with the date/timestamp in its name. I need only 1 file into which all the temperatures are written.