I have written a small bash script (datalogger.sh) to store the mqtt data on to SD card inside a linux machine. The bash script is as below:-
#!/bin/bash
fileNumber=1
temp=1 // flag to check and create new files
fileName="Data"
while [ $temp -le 1 ]
do
if [ -f "/media/card/$fileName$fileNumber.txt" ]
then
((fileNumber++))
else
touch "/media/card/$fileName$fileNumber.txt"
mosquitto_sub -v -t "gateway/+/rx" | tee /media/card/$fileName$fileNumber.txt
temp=2
fi
done
The bash script works totally fine if i run it with the following command
./datalogger.sh
As of next step, i used the update-rc.d datalogger.sh defaults
so that on boot the bash script automatically runs. However, i only get the empty text files. Could anyone guide me, what mistake i am making?
Best Regards,