Script och service för att övervaka och synka ändringar till filen

This commit is contained in:
2025-01-23 21:45:59 +01:00
parent fb0803d7a4
commit 30c0fe861b
2 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
[Unit]
Description=Synka Fredriks org-todo-pwa
[Service]
ExecStart=/home/fredrik/bin/todo-watcher.sh
Restart=always
User=fredrik
[Install]
WantedBy=multi-user.target

24
scripts/todo-watcher.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
# Set paths to the files
SOURCE_FILE="/srv/swarm/org-todo-pwa/data/tasks.org"
DEST_FILE="/home/fredrik/org-mode/pwa.org"
# Watch for multiple events on the source file (e.g., modify, close_write, attrib)
inotifywait -m -e modify "$SOURCE_FILE" | while read path action file; do
# Compare the full path of the file being watched to the source file
if [ "$path$file" == "$SOURCE_FILE" ]; then
# Check if the file is empty (size 0) to avoid appending empty content
if [ -s "$SOURCE_FILE" ]; then
# Append the contents of the source file to the destination file
cat "$SOURCE_FILE" >> "$DEST_FILE"
# Empty the source file
> "$SOURCE_FILE"
echo "Appended contents of $SOURCE_FILE to $DEST_FILE and emptied the source file."
else
echo "$SOURCE_FILE is empty, skipping append."
fi
fi
done