I looked in /lib/udev/rules.d for examples of disk related rules. On an Ubuntu system one rule file provides the environment variable ID_FS_UUID_ENC which you can use in own rule files.
Thus I put a custom rule file under /etc/udev/rules.d/foodevice.rules. Since it is not prefixed with a number, it is ran at last by udev. Btw, the udev daemon watches /etc/udev/rules.d for changes such that you don't need to restart it on file changes.
The content of /etc/udev/rules.d/foodevice.rules is:
ACTION=="add", KERNEL=="sd*[!0-9]", ENV{ID_FS_UUID_ENC}=="FFFF-AAAF",
RUN+="/usr/bin/sudo -u juser /home/juser/path/script.sh"
(this is one rule - you have to remove the newline after the ENV clause because udev does not have a line continuation mechanism)
A program started by udev blocks the daemon - thus it shouldn't run for a long time. I solved it via at - i.e. via detaching from the process doing the real work:
$ cat /home/juser/path/script.sh
#!/bin/sh
echo /path/to/mountcopystuff.sh | at now
udevadm trigger? Does your system use udev? If you want to run a script when anything is plugged in, remove all the conditions (the clauses with==) (maybe the syntax requires one condition, I'm not sure; if it does, useKERNEL=="*"). – Gilles 'SO- stop being evil' Feb 22 '13 at 15:28at. See "running external programs" on http://www.reactivated.net/writing_udev_rules.html – cheshirekow Jun 03 '18 at 01:15.rulesand the files in the directory are read in a lexical order (convention uses numeric prefix to order them), and they can be beneath/etc/,/usr/libor/run. For more, RTFM. – starfry Dec 21 '18 at 09:19