I have a start up shell script which reads a value from the file, increments it by 1 and writes it back. After that I do power-cycling of the system(switch off and switch on the power supply). I am trying to record the number of reboots using this way. But I find that the file counter always remains at 1. If I do the reboot using the reboot command, the counter in the file increments properly. Is this because the file write is buffered and delayed by the kernel. Is there a way to force it to write immediately?
The rc.user file is as follows:
cd /root
bash bootcounter.sh
sleep 1
bootcounter.sh is as follows
rebootcount=$(<bootcount)
rebootcount=$(($rebootcount+1))
echo $rebootcount >bootcount
Thanks…
You want the sync command. This should flush all the file systems.
You should probably use a full path to bootcount, though.