From 14560d39ceb3317f5adba4703231b2493eb0effa Mon Sep 17 00:00:00 2001 From: Yujing Zheng Date: Mon, 19 Aug 2024 19:49:24 +0800 Subject: [PATCH] update logs path --- examples/watch-and-upload/watch-and-upload.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/watch-and-upload/watch-and-upload.sh b/examples/watch-and-upload/watch-and-upload.sh index 5ef477c..e9649aa 100755 --- a/examples/watch-and-upload/watch-and-upload.sh +++ b/examples/watch-and-upload/watch-and-upload.sh @@ -6,6 +6,7 @@ set -o pipefail if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace fi +trap 'echo "正在退出..."; exit' INT if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then echo '用法: ./watch-and-upload.sh [WATCH_DIR] @@ -32,8 +33,8 @@ if [ ! -d "$WATCH_DIR" ]; then fi # 定义日志文件 -UPLOAD_LOGS="$WATCH_DIR/.UPLOAD_LOGS" -RECORD_LOGS="$WATCH_DIR/.RECORD_LOGS" +UPLOAD_LOGS="/tmp/.UPLOAD_LOGS" +RECORD_LOGS="/tmp/.RECORD_LOGS" # 确保日志文件存在 touch "$UPLOAD_LOGS" "$RECORD_LOGS" @@ -93,7 +94,6 @@ process_file() { if cocli record upload "$record_id" "$file"; then sed -i "\|${file//\//\\/}|d" "$UPLOAD_LOGS" echo "$(date +'%Y-%m-%d %H:%M:%S')|$file|$md5sum" >>"$UPLOAD_LOGS" - echo "已上传: $file" else echo "上传失败: $file" >&2 fi @@ -116,16 +116,15 @@ main() { initialize echo "开始监控目录: $WATCH_DIR" - fswatch --latency=5 --event "Created" --event "Updated" --event "MovedTo" -0 -r \ + fswatch --latency=5.0 --event Created --event Updated --event MovedTo -0 -r \ -e "(/|^)\.[^/]*$" \ -e "/sed.*\.tmp$" \ - "$WATCH_DIR" | while read -d "" file; do + "$WATCH_DIR" | while read -d "" event; do - echo $file - - if [ -f "$file" ] && [[ "$(basename "$file")" != .* ]]; then - echo "正在处理 $file" - process_file "$file" + echo $event + if [ -f "$event" ] && [[ "$(basename "$event")" != .* ]]; then + echo "正在处理 $event" + process_file "$event" fi done }