25 lines
867 B
Bash
Executable File
25 lines
867 B
Bash
Executable File
#!/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
|