Script och service för att övervaka och synka ändringar till filen
This commit is contained in:
10
scripts/org-todo-pwa.service
Normal file
10
scripts/org-todo-pwa.service
Normal 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
24
scripts/todo-watcher.sh
Executable 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
|
||||||
Reference in New Issue
Block a user