Untitled
unknown
plain_text
a month ago
1.7 kB
34
No Index
#!/bin/bash # Directory to watch WATCH_DIR="/mnt/user/data/Media/Comics" # Command to execute when changes are detected UPDATE_COMMAND="docker exec YACReaderLibraryServer YACReaderLibraryServer update-library /comics" # Print startup message echo "=====================================" echo "📂 Monitoring: $WATCH_DIR" echo "🚫 Excluding: .yacreaderlibrary, .zzz_check, cbr2cbz" echo "🔄 Triggering on: create, close_write, delete, move" echo "⏳ Waiting 10 seconds after last event before updating..." echo "🚀 Running in background..." echo "=====================================" # Background timer process ID TIMER_PID="" # Function to trigger the update after a 10-second delay trigger_update() { sleep 10 # Wait 10 seconds after the last event echo "🔄 Updating YACReader Library..." eval $UPDATE_COMMAND echo "✅ Update complete." echo "-------------------------------------" TIMER_PID="" # Clear the PID after update runs } # Start monitoring in the background inotifywait -m -r -e create,close_write,delete,move --timefmt '%Y-%m-%d %H:%M:%S' --format '%T | %w%f | %e' $WATCH_DIR --exclude '/\..+' | while read -r timestamp file event; do echo "🔍 Change detected: [$timestamp] $file ($event)" # Kill previous timer if still running if [[ -n "$TIMER_PID" && -e "/proc/$TIMER_PID" ]]; then echo "🛑 Stopping previous timer (PID: $TIMER_PID)" kill "$TIMER_PID" 2>/dev/null wait "$TIMER_PID" 2>/dev/null fi # Start a new timer in the background trigger_update & TIMER_PID=$! echo "⏳ New timer started (PID: $TIMER_PID)" done
Editor is loading...
Leave a Comment