-1

I would like to execute a backup script with rsync everytime a specific hard drive is plugged to my computer on ubuntu 16.04. However I would like the user to be prompted if the backup should run or not and then he should be able to see the rsync output live in a terminal.

What I did so far:

  • I created a rule at /etc/udev/rules.d/backup_on_mount.rules

    ACTION=="add", ATTRS{idVendor}=="1058", ATTRS{idProduct}=="0820", RUN+="/path/to/my/script/backup_on_mount.sh"
    
  • I created the backup_on_mount.sh script and made it executable

However I did not succeed in popping a new terminal window with my script running in it when I plug my hard drive.

Does anybody have an idea on how to begin ?

Thank you

Alex P.
  • 30,437
  • 17
  • 118
  • 169
Louis M
  • 4,036
  • 4
  • 21
  • 25
  • 1
    Use `zenity` in your script. – Ipor Sircer Sep 26 '16 at 19:44
  • What should happen if your hard drive is plugged in while no interactive user session exists? – Charles Duffy Sep 29 '16 at 23:22
  • ...to be clear, I'm staunchly in the this-is-a-bad-idea camp. Making your daemons aware of foreground interactive user sessions is actually liable if not likely to break in the future, if/as your OS vendor implements SELinux policy to keep processes out of things they shouldn't be in (and under normal circumstances, connecting to an X server from a udev-spawned process is definitely a thing that good security policy will prevent). – Charles Duffy Sep 29 '16 at 23:24
  • You're going to need to dig around to find the DISPLAY variable used by your current session, and the Xauthority file or other cookies used to authenticate to the X server. It's doable, but fragile and ugly; if all you want is to inform the user of start/completion/status, I'd suggest using [dbusnotify](http://software.clapper.org/dbusnotify/man/dbusnotify.1.html). Even then [some contortions will still be needed](http://www.hauweele.net/~gawen/blog/?p=834). – Charles Duffy Sep 29 '16 at 23:25
  • Thanks for the ideas, I actually want to execute the script ONLY IF I have an explicit confirmation by the current user. – Louis M Sep 30 '16 at 16:07

1 Answers1

0

You are not supposed to run anything that long from udev rules directly. One way of dissociating your long running script from the udev rule is by scheduling it (with at -M now command for example) instead of running it directly. The proper way of finding the right DISPLAY to open the new terminal depends on your desktop environment

Alex P.
  • 30,437
  • 17
  • 118
  • 169