From a8924be67e3f2a8eb58c13c7c921c8852cd824b0 Mon Sep 17 00:00:00 2001
From: Andreas Romeyke <art1@andreas-romeyke.de>
Date: Wed, 12 Oct 2022 17:17:38 +0200
Subject: [PATCH] - added daemon mode using inotifywait

---
 validate_workflow.sh | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/validate_workflow.sh b/validate_workflow.sh
index 6a94bc4..85fb37a 100755
--- a/validate_workflow.sh
+++ b/validate_workflow.sh
@@ -397,8 +397,17 @@ if [ "$WITH_PIPE" -eq 1 ]; then
     rm -f "$filename" || error "could not remove temporary file '$filename'"
 else 
     if [ "$WITH_DAEMON" -eq 1 ]; then
+        # TODO: protect DAEMON from STRG-C for clean shutdown
         # echo daemon mode, use inotify to watch changes
         debug "starting daemon"
+        scan_dir "$WATCH_FOLDER" # to clean up existing files
+        /usr/bin/inotifywait --monitor --recursive --event create \
+            --event attrib --event moved_to --format "%w%f" "$WATCH_FOLDER" \
+            | while read -r filename; do
+        debug "called inotifywait using /usr/bin/inotifywait --monitor
+        --recursive --event create --event attrib --event moved_to --format '%f' $WATCH_FOLDER"
+        scan_file "$filename"
+    done
         debug "stopping daemon"
     else
         # cli mode, scan watch folder once
-- 
GitLab