53 lines
1.3 KiB
Bash
53 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
WATCH_DIR="./public/photos/Fabio/original"
|
|
DELAY=10
|
|
LOCK_FILE="./Fabio.scan"
|
|
|
|
echo "Monitoro: $WATCH_DIR"
|
|
|
|
LAST_EVENT_TIME=0
|
|
|
|
# Thread che controlla l'inattività
|
|
check_inactivity() {
|
|
while true; do
|
|
sleep 1
|
|
|
|
# Se non è mai arrivato un evento, continua ad aspettare
|
|
if (( LAST_EVENT_TIME == 0 )); then
|
|
continue
|
|
fi
|
|
|
|
NOW=$(date +%s)
|
|
DIFF=$(( NOW - LAST_EVENT_TIME ))
|
|
|
|
# Se non sono passati 10 secondi → continua ad aspettare
|
|
if (( DIFF < DELAY )); then
|
|
continue
|
|
fi
|
|
|
|
# Se esiste il lock file → aspetta altri 10 secondi
|
|
if [[ -f "$LOCK_FILE" ]]; then
|
|
echo "Lock presente ($LOCK_FILE), attendo altri $DELAY secondi..."
|
|
sleep $DELAY
|
|
continue
|
|
fi
|
|
|
|
# QUI: 10 secondi di quiete + lock libero → esegui
|
|
echo "modificato Fabio (nessuna attività per $DELAY secondi)"
|
|
touch "$LOCK_FILE"
|
|
|
|
# Resetta il timer per evitare ripetizioni
|
|
LAST_EVENT_TIME=0
|
|
done
|
|
}
|
|
|
|
# Avvia il thread di controllo inattività
|
|
check_inactivity &
|
|
|
|
# Listener degli eventi
|
|
inotifywait -m -r -e create,modify,delete "$WATCH_DIR" |
|
|
while read path action file; do
|
|
echo "Evento rilevato: $action su $file"
|
|
LAST_EVENT_TIME=$(date +%s)
|
|
done
|