嵌入式爱好者

检测文件占用结束保存系统的小脚本

2023-8-31 20:23| 发布者: zhichao| 查看: 82| 评论: 0

类目: A40i/T3系列产品  >  Linux     文档编号: 1118

有些时候我们应用修改文件后直接给开发板断电,可能会因为没保存导致文件埙坏,可以检测文件占用,在不占用的情况下保存
例如使用dd if=/dev/zero of=/root/test bs=1M count=500 conv=fsync &写数据到/root/test。
可用下面脚本检测文件写完并保存。执行./check.sh /root/test。
check.sh脚本内容如下
#!/bin/bash
return_code=0
while [[ "$return_code" -eq 0 ]]; do
sleep 1
output=$(fuser $1)
return_code=$?

if [ "$return_code" -ne 0 ]; then
echo "The file is not being used"
sync
else
if [ -n "$output" ]; then
echo "$output"

echo "The file is being used"
else
echo "A fatal error occured !"
fi
fi
done



已解决

未解决

只是看看

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2024-5-1 16:02

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

返回顶部