Skip to content

Commit

Permalink
update logs path
Browse files Browse the repository at this point in the history
  • Loading branch information
yujingz committed Aug 19, 2024
1 parent 87df801 commit 14560d3
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions examples/watch-and-upload/watch-and-upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 14560d3

Please sign in to comment.