Backup_the_Backup with GUI and running as root
instead of polling the existence of a flag file, i would like to use inotify. the flag-file should be put into /var/spool/<username> or the like
You can use inotifywait (from the inotify-tools package) to watch for the creation or modification of a flag file in /var/spool/<username>, triggering your dialog and subsequent actions when the file appears—without polling. Here’s how to implement it:
1. Choose a Flag File Location
Create a directory for your user under /var/spool:
sudo mkdir -p /var/spool/<username> sudo chown <username>:<username> /var/spool/<username>
Replace <username> with the actual user.
Set your flag file path (e.g., /var/spool/<username>/device-plugged).
2. udev Rule Triggers Flag File Creation
Update your udev rule to run a script that creates the flag file:
ACTION=="add", ENV{ID_FS_UUID}=="YOUR-FS-UUID", RUN+="/path/to/create-flag.sh"
create-flag.sh:
#!/bin/bash touch /var/spool/<username>/device-plugged chown <username>:<username> /var/spool/<username>/device-plugged
Again, replace <username> with the actual user.
3. User-Space Script Watches with inotify
Write a script that runs in your user’s session (e.g., from .xprofile or your desktop environment’s autostart):
#!/bin/bash
FLAG_FILE="/var/spool/<username>/device-plugged"
inotifywait -m -e create --format '%w%f' "$(dirname "$FLAG_FILE")" | while read FILE
do
if [[ "$FILE" == "$FLAG_FILE" ]]; then
zenity --question --text="Device detected. Start rsync?" && sudo /usr/local/bin/start-rsync.sh
rm -f "$FLAG_FILE"
fi
done
This script uses inotifywait to watch the directory for file creation, then triggers your dialog and action when the flag file appears^2.
4. Ensure inotify-tools is Installed
Install the required package:
sudo apt-get install inotify-tools # Debian/Ubuntu # or sudo yum install inotify-tools # CentOS/RHEL
5. Start the Watcher Script
Add the watcher script to your user’s autostart, .xprofile, or similar so it runs on login^2.