Files
devops/docker/paperless/plugins/consume.sh
2025-11-13 08:34:28 +08:00

48 lines
1.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
SRC="/volume1/docker/sharedata/stock_data/pdfs"
DST="/volume1/docker/sharedata/stock_data/em_reports_consume"
LOG="./log/paperless.log"
TARGET_UID=1000
TARGET_GID=1000
# 检查目录
if [ ! -d "$SRC" ]; then
echo "$(date '+%F %T') [ERROR] 源目录不存在: $SRC" | tee -a "$LOG"
exit 1
fi
if [ ! -d "$DST" ]; then
echo "$(date '+%F %T') [ERROR] 目标目录不存在: $DST" | tee -a "$LOG"
exit 1
fi
# 关键添加检查并创建log目录-p 确保父目录存在,无报错)
LOG_DIR=$(dirname "$LOG") # 提取日志文件所在目录(即 ./log
if [ ! -d "$LOG_DIR" ]; then
mkdir -p "$LOG_DIR"
echo "$(date '+%F %T') [INFO] log目录不存在已创建: $LOG_DIR" | tee -a "$LOG"
fi
COUNT=0
for f in "$SRC"/*.pdf; do
[ -f "$f" ] || continue
# 移动 + 改属主 + 改权限
if install -D -o "$TARGET_UID" -g "$TARGET_GID" -m 644 "$f" "$DST"; then
rm -f "$f"
echo "$(date '+%F %T') [OK] Moved: $f" >> "$LOG"
((COUNT++))
# 每移动10个文件输出进度到屏幕同时写入日志
if (( COUNT % 100 == 0 )); then
PROGRESS_MSG="$(date '+%F %T') [PROGRESS] 已移动 $COUNT 个文件"
echo "$PROGRESS_MSG" | tee -a "$LOG"
fi
else
echo "$(date '+%F %T') [FAIL] Failed: $f" >> "$LOG"
fi
done
echo "$(date '+%F %T') [INFO] 搬运完成,共移动 $COUNT 个文件" | tee -a "$LOG"