我有一个启动的shell脚本,它从文件中读取一个值,将其加1并写回。 之后,我进行系统的电源循环(关闭并打开电源)。 我试图用这种方法记录重新启动的次数。 但是我发现文件计数器始终保持为1.如果使用reboot命令执行重新引导,则文件中的计数器会正确递增。 这是因为文件写入是由内核缓冲和延迟的。 有没有办法强制它立即写入?
rc.user文件如下所示:
cd /root bash bootcounter.sh sleep 1bootcounter.sh如下
rebootcount=$(<bootcount) rebootcount=$(($rebootcount+1)) echo $rebootcount >bootcount谢谢...
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 1bootcounter.sh is as follows
rebootcount=$(<bootcount) rebootcount=$(($rebootcount+1)) echo $rebootcount >bootcountThanks...
最满意答案
你想要同步命令。 这应该刷新所有的文件系统。
count=$( cat bootcount ) echo $( expr $count + 1 ) > bootcount sync不过,您应该使用完整路径来引导帐户。
You want the sync command. This should flush all the file systems.
count=$( cat bootcount ) echo $( expr $count + 1 ) > bootcount syncYou should probably use a full path to bootcount, though.
更多推荐
发布评论