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/&lt;username&gt;, triggering your dialog and subsequent actions when the file appears—without polling. Here’s how to implement it:

Create a directory for your user under /var/spool:

sudo mkdir -p /var/spool/<username>
sudo chown <username>:<username> /var/spool/<username>

Replace &lt;username&gt; with the actual user.

Set your flag file path (e.g., /var/spool/&lt;username&gt;/device-plugged).

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 &lt;username&gt; with the actual user.

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.

Install the required package:

sudo apt-get install inotify-tools   # Debian/Ubuntu
# or
sudo yum install inotify-tools       # CentOS/RHEL

Add the watcher script to your user’s autostart, .xprofile, or similar so it runs on login^2.

  • computer/ubuntu/backup_the_backup_gui.txt
  • Last modified: 2025/06/17 06:44
  • by spring