RepairSd.sh
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
AUDIO_DIR="/root/sdcard/audio"
MOUNT_POINT="/root/sdcard"
JZLOG="/root/sdcard/JZLOG"
LOG="/root/sdcard/Logs"
DEVICE=$(mount | grep "$MOUNT_POINT" | awk '{print $1}')
# 检查sd开文件系统是否可写
check_sdCard_filesystem_writable() {
if ! touch "$MOUNT_POINT"/.test_write 2>/dev/null; then
echo "文件系统已变成只读,尝试重新挂载..."
mount -o remount rw "$MOUNT_POINT" || {
echo "重新挂载失败,请检查文件系统!"
exit 1
}
return 1
fi
return 0
}
# 遍历audio下的所有文件,检查是否读取后是否能正常写入sd卡
# 检查音频文件
check_audio_files() {
if [ -d "$AUDIO_DIR" ]; then
echo "开始检查音频文件..."
find "$AUDIO_DIR" -type f -print0 | while IFS= read -r -d '' file; do
echo "检查到文件${file}"
ffprobe "$file" > /dev/null 2>&1
# 检测sd卡还能否写入
if ! touch "$MOUNT_POINT"/.test_write 2>/dev/null; then
echo "文件系统已变成只读,尝试重新挂载..."
# 重新挂载
mount -o remount rw /root/sdcard
# 删除损坏的文件
rm -f ${file}
else
echo "文件系统正常,继续检查下一个文件"
fi
done
else
echo "音频目录不存在: $AUDIO_DIR"
fi
}
# 1、删除测试读取文件
rm -f "$MOUNT_POINT"/.test_write
# 检查文件系统是否可写, 如果不可写,先恢复
check_sdCard_filesystem_writable
# 检查音频文件
check_audio_files
echo "检测完成!"