I tried to write a little bash code to write a temperaturelog. The into the logging file 100 timepoints and measuring points are written, then the data is moved to a temporary file and it should begin to record again into the original file. The temporary file is removed every 100 seconds because I only need the last minutes of record and want to prevent garbage.
Besides that the code might look unnecessarily complicated (I am a beginner) - Where is the mistake? I expected the counter (printed just to see what is going on) would count to 100 but it only prints out:
1
2
and it writes only two timepoints instead of 100 into the files. Here is the code:
#!/bin/bash
COUNTER=0
#Initial temporary file is created
echo '' > temperaturelogtemporary.txt;
#100 timepoints are written into temperaturelog.txt
while true; do
echo `date` '->' `acpi -t`>> temperaturelog.txt;
sleep 1;
#as soon as 100 timepoints are recorded...
if [[ $COUNTER > 100 ]];
then
#...the old temporary file is removed and
#the last records are renamed into a new temporary file
rm temperaturelogtemporary.txt;
mv temperaturelog.txt temperaturelogtemporary.txt;
COUNTER=0;
fi
COUNTER=$(($COUNTER + 1));
echo $COUNTER;
done